add TransactionHandle::set

This commit is contained in:
soruh 2023-08-15 00:16:19 +02:00
parent 1383d615de
commit 238b00348e
2 changed files with 7 additions and 0 deletions

View File

@ -41,6 +41,7 @@ impl Str {
}
}
// TODO: remove these impls for all datatypes
impl FilePointer<Str> {
pub fn set<R>(self, transaction: &mut TransactionHandle<R>, s: &str) -> FilePointer<Str> {
let new_str = transaction.read::<Str>(self).set(transaction, s);

View File

@ -136,6 +136,12 @@ impl<'t, R> TransactionHandle<'t, R> {
(FilePointer::from_range(range), data)
}
pub fn set<T: AsBytes + FromBytes>(&mut self, at: FilePointer<T>, value: T) -> FilePointer<T> {
let (ptr, data) = self.modify(at);
*data = value;
ptr
}
pub fn allocate_range(&mut self, length: u64) -> (FileRange, &mut [u8]) {
unsafe {
let range = self.db.allocate(length);