Struct d4_framefile::RandFile 
source · [−]pub struct RandFile<T> { /* private fields */ }Expand description
The file object that supports random access. Since in D4 file, we actually use a random access file mode, which means all the read and write should provide the address. And this is the object that provides the low level random access interface.
At the same time, this RandFile object is synchronized, which means we guarantee the thread safety that each block of data is written to file correctly.
The rand file provides a offset-based file access API and data can be read and write from the specified address in blocks. But rand file itself doesn’t tracking the block size and it’s the upper layer’s responsibility to determine the correct block beginning.
Implementations
sourceimpl<T: Read + Write + Seek> RandFile<T>
 
impl<T: Read + Write + Seek> RandFile<T>
sourcepub fn for_read_write(inner: T) -> Self
 
pub fn for_read_write(inner: T) -> Self
The convenient helper function to create a read-write random file
inner: The underlying implementation for this backend
sourceimpl<T: Write + Seek> RandFile<T>
 
impl<T: Write + Seek> RandFile<T>
sourcepub fn append_block(&mut self, buf: &[u8]) -> Result<u64>
 
pub fn append_block(&mut self, buf: &[u8]) -> Result<u64>
Append a block to the random accessing file the return value is the relative address compare to the last accessed block.
buf: The data buffer that needs to be writereturns: The absolute address of the block that has been written to the file.
sourcepub fn update_block(&mut self, offset: u64, buf: &[u8]) -> Result<()>
 
pub fn update_block(&mut self, offset: u64, buf: &[u8]) -> Result<()>
Update a data block with the given data buffer.
offset: The offset of the data blockbuf: The data buffer to write
sourcepub fn reserve_block(&mut self, size: usize) -> Result<u64>
 
pub fn reserve_block(&mut self, size: usize) -> Result<u64>
Reserve some space in the rand file. This is useful when we want to reserve a data block
for future use. This is very useful for some volatile data (for example the directory block), etc.
And later, we are able to use update_block function to keep the reserved block up-to-dated
sourceimpl<T: Read + Seek> RandFile<T>
 
impl<T: Read + Seek> RandFile<T>
pub fn size(&mut self) -> Result<u64>
sourcepub fn read_block(&mut self, addr: u64, buf: &mut [u8]) -> Result<usize>
 
pub fn read_block(&mut self, addr: u64, buf: &mut [u8]) -> Result<usize>
Read a block from the random accessing file the size of the buffer slice is equal to the number of bytes that is requesting But there might not be enough bytes available for read, thus we always return the actual number of bytes is loaded
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for RandFile<T>
impl<T> Send for RandFile<T> where
    T: Send, 
impl<T> Sync for RandFile<T> where
    T: Send, 
impl<T> Unpin for RandFile<T>
impl<T> UnwindSafe for RandFile<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
    T: ?Sized, 
 
impl<T> BorrowMut<T> for T where
    T: ?Sized, 
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
 
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
    T: Clone, 
 
impl<T> ToOwned for T where
    T: Clone, 
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
 
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
 
pub fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more