pub trait Blob:
Clone
+ Send
+ Sync
+ 'static {
// Required methods
fn read_at_buf(
&self,
offset: u64,
len: usize,
bufs: impl Into<IoBufsMut> + Send,
options: ReadOptions,
) -> impl Future<Output = Result<IoBufsMut, Error>> + Send;
fn read_at(
&self,
offset: u64,
len: usize,
options: ReadOptions,
) -> impl Future<Output = Result<IoBufsMut, Error>> + Send;
fn write_at(
&self,
offset: u64,
bufs: impl Into<IoBufs> + Send,
options: WriteOptions,
) -> 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;
fn start_sync(&self) -> impl Future<Output = Handle<()>> + 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.
§Durability
After a crash, a write not covered by a completed Blob::sync may be torn: any subset of its bytes may be durable. Bytes outside the written range remain unchanged.
Required Methods§
Sourcefn read_at_buf(
&self,
offset: u64,
len: usize,
bufs: impl Into<IoBufsMut> + Send,
options: ReadOptions,
) -> impl Future<Output = Result<IoBufsMut, Error>> + Send
fn read_at_buf( &self, offset: u64, len: usize, bufs: impl Into<IoBufsMut> + Send, options: ReadOptions, ) -> impl Future<Output = Result<IoBufsMut, Error>> + Send
Read exactly len bytes at offset into caller-provided buffers.
Returns the same buffers with their chunk layout preserved.
§Panics
Panics if len exceeds the total capacity of bufs.
Sourcefn read_at(
&self,
offset: u64,
len: usize,
options: ReadOptions,
) -> impl Future<Output = Result<IoBufsMut, Error>> + Send
fn read_at( &self, offset: u64, len: usize, options: ReadOptions, ) -> impl Future<Output = Result<IoBufsMut, Error>> + Send
Read exactly len bytes at offset.
To reuse a buffer(s), use Blob::read_at_buf.
Sourcefn write_at(
&self,
offset: u64,
bufs: impl Into<IoBufs> + Send,
options: WriteOptions,
) -> impl Future<Output = Result<(), Error>> + Send
fn write_at( &self, offset: u64, bufs: impl Into<IoBufs> + Send, options: WriteOptions, ) -> impl Future<Output = Result<(), Error>> + Send
Write every remaining byte in bufs to the blob at offset.
The buffers are treated as one logical byte sequence in chunk order.
Sourcefn resize(&self, len: u64) -> impl Future<Output = Result<(), Error>> + Send
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.
Sourcefn sync(&self) -> impl Future<Output = Result<(), Error>> + Send
fn sync(&self) -> impl Future<Output = Result<(), Error>> + Send
Ensure all pending data is durably persisted.
Sourcefn start_sync(&self) -> impl Future<Output = Handle<()>> + Send
fn start_sync(&self) -> impl Future<Output = Handle<()>> + Send
Request that all pending data is durably persisted.
Awaiting this future waits until the sync has started. Awaiting the returned
Handle waits for the same durability guarantee as Blob::sync.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".