[][src]Struct d4_framefile::RandFile

pub struct RandFile<'a, Mode: AccessMode, T: 'a> { /* fields omitted */ }

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]

pub fn lock(&mut self, update_fn: Box<dyn FnOnce() + Send + 'a>) -> Result<Self>[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]

pub fn mmap(&self, offset: u64, size: usize) -> Result<MappingHandle>[src]

impl<T: CanRead<File> + CanWrite<File>, '_> RandFile<'_, T, File>[src]

pub fn mmap_mut(&mut self, offset: u64, size: usize) -> Result<MappingHandleMut>[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 write
  • returns: 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 block
  • buf: 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]

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

impl<'a, Mode, T> Send for RandFile<'a, Mode, T> where
    Mode: Send,
    T: Send

impl<'a, Mode, T> Sync for RandFile<'a, Mode, T> where
    Mode: Sync,
    T: Send

impl<'a, Mode, T> Unpin for RandFile<'a, Mode, T> where
    Mode: Unpin

impl<'a, Mode, T> UnwindSafe for RandFile<'a, Mode, T> where
    Mode: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.