[−][src]Struct d4_framefile::RandFile
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 type parameter Mode is served as a type marker that identify the ability of this
file.
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
impl<'a, M: AccessMode, T: 'a> RandFile<'a, M, T>[src]
impl<T: Read + Seek, '_> RandFile<'_, ReadOnly, T>[src]
pub fn for_read_only(inner: T) -> Self[src]
The convenient helper function to create a read-only random file
inner: The underlying implementation for this backend
impl<T: Read + Write + Seek, '_> RandFile<'_, ReadWrite, T>[src]
pub fn for_read_write(inner: T) -> Self[src]
The convenient helper function to create a read-write random file
inner: The underlying implementation for this backend
impl<T: CanRead<File>, '_> RandFile<'_, T, File>[src]
impl<T: CanRead<File> + CanWrite<File>, '_> RandFile<'_, T, File>[src]
impl<Mode: CanWrite<T>, T: Write + Seek, '_> RandFile<'_, Mode, T>[src]
pub fn append_block(&mut self, buf: &[u8]) -> Result<u64>[src]
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.
pub fn update_block(&mut self, offset: u64, buf: &[u8]) -> Result<()>[src]
Update a data block with the given data buffer.
offset: The offset of the data blockbuf: The data buffer to write
pub fn reserve_block(&mut self, size: usize) -> Result<u64>[src]
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
impl<Mode: CanRead<T>, T: Read + Seek, '_> RandFile<'_, Mode, T>[src]
pub fn size(&mut self) -> Result<u64>[src]
pub fn read_block(&mut self, addr: u64, buf: &mut [u8]) -> Result<usize>[src]
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
impl<M: AccessMode, T, '_> Clone for RandFile<'_, M, T>[src]
fn clone(&self) -> Self[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
impl<M: AccessMode, T, '_> Drop for RandFile<'_, M, T>[src]
Auto Trait Implementations
impl<'a, Mode, T> RefUnwindSafe for RandFile<'a, Mode, T> where
Mode: RefUnwindSafe,
Mode: RefUnwindSafe,
impl<'a, Mode, T> Send for RandFile<'a, Mode, T> where
Mode: Send,
T: Send,
Mode: Send,
T: Send,
impl<'a, Mode, T> Sync for RandFile<'a, Mode, T> where
Mode: Sync,
T: Send,
Mode: Sync,
T: Send,
impl<'a, Mode, T> Unpin for RandFile<'a, Mode, T> where
Mode: Unpin,
Mode: Unpin,
impl<'a, Mode, T> UnwindSafe for RandFile<'a, Mode, T> where
Mode: UnwindSafe,
Mode: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,