Skip to main content

Storage

Trait Storage 

Source
pub trait Storage {
Show 16 methods // Required methods fn name(&self) -> Name; fn names(&self, at: &Entry) -> String; fn residency(&self) -> Residency; fn read<'a>( &'a self, at: &'a Entry, ) -> impl Future<Output = Result<Option<Vec<u8>>>> + 'a; fn exists<'a>( &'a self, at: &'a Entry, ) -> impl Future<Output = Result<bool>> + 'a; fn write<'a>( &'a self, at: &'a Entry, bytes: &'a [u8], ) -> impl Future<Output = Result<()>> + 'a; fn append<'a>( &'a self, at: &'a Entry, bytes: &'a [u8], ) -> impl Future<Output = Result<()>> + 'a; fn truncate<'a>( &'a self, at: &'a Entry, len: u64, ) -> impl Future<Output = Result<()>> + 'a; fn list<'a>( &'a self, dir: &'a Entry, ) -> impl Future<Output = Result<Vec<String>>> + 'a; fn remove<'a>( &'a self, at: &'a Entry, ) -> impl Future<Output = Result<()>> + 'a; fn create_dir<'a>( &'a self, dir: &'a Entry, ) -> impl Future<Output = Result<()>> + 'a; fn rename<'a>( &'a mut self, to: &'a Name, ) -> impl Future<Output = Result<()>> + 'a; fn discard(&self) -> impl Future<Output = Result<()>> + '_; // Provided methods fn disk_path(&self) -> Option<&Path> { ... } fn claim(&self, now: WallTime) -> impl Future<Output = Result<Claim>> + '_ { ... } fn release(&self) { ... }
}
Expand description

Where one container’s bytes live.

Required Methods§

Source

fn name(&self) -> Name

What this container is called.

Source

fn names(&self, at: &Entry) -> String

What a report calls at — a platform path where there is one. Not a promise that anything is there.

Source

fn residency(&self) -> Residency

Source

fn read<'a>( &'a self, at: &'a Entry, ) -> impl Future<Output = Result<Option<Vec<u8>>>> + 'a

The bytes at at, or None where nothing is — which is not the same as a read that did not work.

Source

fn exists<'a>( &'a self, at: &'a Entry, ) -> impl Future<Output = Result<bool>> + 'a

Whether anything stands at at. Separate from Self::read because a payload is filed under a content hash, so the answer is all a write needs — and reading a megabyte to learn it is already there is the one thing that would make every commit cost the artwork on the page.

Source

fn write<'a>( &'a self, at: &'a Entry, bytes: &'a [u8], ) -> impl Future<Output = Result<()>> + 'a

Whole file or nothing: a reader caught mid-write sees the previous contents, never half of each.

Source

fn append<'a>( &'a self, at: &'a Entry, bytes: &'a [u8], ) -> impl Future<Output = Result<()>> + 'a

Add bytes to the end of at, durably before returning.

Source

fn truncate<'a>( &'a self, at: &'a Entry, len: u64, ) -> impl Future<Output = Result<()>> + 'a

Source

fn list<'a>( &'a self, dir: &'a Entry, ) -> impl Future<Output = Result<Vec<String>>> + 'a

What dir holds, by name, in no particular order.

Source

fn remove<'a>(&'a self, at: &'a Entry) -> impl Future<Output = Result<()>> + 'a

Source

fn create_dir<'a>( &'a self, dir: &'a Entry, ) -> impl Future<Output = Result<()>> + 'a

Make dir a place entries can be written.

Source

fn rename<'a>( &'a mut self, to: &'a Name, ) -> impl Future<Output = Result<()>> + 'a

Call this container something else, leaving everything in it where it is — which is what renaming the document means.

Source

fn discard(&self) -> impl Future<Output = Result<()>> + '_

Remove the container itself. Only ever asked of one that has been emptied.

Provided Methods§

Source

fn disk_path(&self) -> Option<&Path>

Where these bytes sit on a filesystem, for a shell that can name one. None for a storage that has no such thing.

Source

fn claim(&self, now: WallTime) -> impl Future<Output = Result<Claim>> + '_

Claim the right to write this container.

The default is the lock entry a container has always carried: a row naming the process that holds it, broken when that process is gone. A storage whose host keeps locks of its own answers from that instead — which is not a nicety in a browser, where nothing can be asked whether the tab that left an entry behind is still there.

Source

fn release(&self)

Give the lock back.

Synchronous where the claim is not, because a container releases its lock as it is dropped and a Drop cannot await. Which is why a storage whose futures are not ready must hold its lock somewhere it can let go of in one call — its host’s lock manager — rather than in the entry the default writes: an entry it could not remove here would outlive every session that took it.

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§