Skip to main content

Blob

Trait Blob 

Source
pub trait Blob:
    Clone
    + Send
    + Sync
    + 'static {
    // Required methods
    fn read_at(
        &self,
        offset: u64,
        buf: impl Into<IoBufsMut> + Send,
    ) -> impl Future<Output = Result<IoBufsMut, Error>> + Send;
    fn write_at(
        &self,
        offset: u64,
        buf: impl Into<IoBufs> + Send,
    ) -> impl Future<Output = Result<(), Error>> + Send;
    fn resize(&self, len: u64) -> impl Future<Output = Result<(), Error>> + Send;
    fn sync(&self) -> impl Future<Output = Result<(), Error>> + Send;
}
Expand description

Interface to read and write to a blob.

To support blob implementations that enable concurrent reads and writes, blobs are responsible for maintaining synchronization.

Cloning a blob is similar to wrapping a single file descriptor in a lock whereas opening a new blob (of the same name) is similar to opening a new file descriptor. If multiple blobs are opened with the same name, they are not expected to coordinate access to underlying storage and writing to both is undefined behavior.

When a blob is dropped, any unsynced changes may be discarded. Implementations may attempt to sync during drop but errors will go unhandled. Call sync before dropping to ensure all changes are durably persisted.

Required Methods§

Source

fn read_at( &self, offset: u64, buf: impl Into<IoBufsMut> + Send, ) -> impl Future<Output = Result<IoBufsMut, Error>> + Send

Read into caller-provided buffer(s) at the given offset.

The caller provides the buffer, and the implementation fills it with data read from the blob starting at offset. Returns the same buffer, filled with data.

§Contract
  • The output IoBufsMut is the same as the input, with data filled from offset
  • The total bytes read equals the total initialized length of the input buffer(s)
Source

fn write_at( &self, offset: u64, buf: impl Into<IoBufs> + Send, ) -> impl Future<Output = Result<(), Error>> + Send

Write buf to the blob at the given offset.

Source

fn resize(&self, len: u64) -> impl Future<Output = Result<(), Error>> + Send

Resize the blob to the given length.

If the length is greater than the current length, the blob is extended with zeros. If the length is less than the current length, the blob is resized.

Source

fn sync(&self) -> impl Future<Output = Result<(), Error>> + Send

Ensure all pending data is durably persisted.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<B: Blob> Blob for Append<B>

Source§

impl<B: Blob> Blob for Write<B>