pub trait AsyncStore {
// Required methods
fn read_log_async(
&self,
name: &str,
) -> impl Future<Output = Result<Vec<u8>>> + WasmCompatSend;
fn append_log_async(
&self,
name: &str,
len: u64,
bytes: &[u8],
) -> impl Future<Output = Result<(), LogWriteError>> + WasmCompatSend;
fn replace_log_async(
&self,
name: &str,
len: u64,
bytes: &[u8],
) -> impl Future<Output = Result<(), LogWriteError>> + WasmCompatSend;
fn read_file_async(
&self,
name: &str,
) -> impl Future<Output = Result<Vec<u8>>> + WasmCompatSend;
fn write_file_async(
&self,
name: &str,
bytes: &[u8],
) -> impl Future<Output = Result<()>> + WasmCompatSend;
}Expand description
A session’s storage reached asynchronously: the part of Store that
load_async and save_async
use, for a store behind a network or a JavaScript promise. Every
Store is one, its calls done when made: a local store pays no thread
hop and no allocation for it. A type that implements Store gets this
from it and cannot have its own (the two impls would overlap): wrap it
in a type of your own instead.
Each method keeps Store’s contract. A name is checked by
check_name (a log name is one part) and may come from a log’s
content, so a store refuses one that does not pass. The two log writes
check the log’s length and write in one step, such as a conditional
UPDATE … WHERE octet_length(bytes) = $len or one IndexedDB
readwrite transaction, never a read followed by a write. An append
adds its bytes whole, or at worst leaves a cut last line, which the next
save sets aside: save_async writes one turn with
one append, so a cancelled or failed save never stores part of one.
io::ErrorKind::NotFound means there is no such log or file.
Its futures are Send natively, and on browser wasm neither they nor
the store need be. A holder that shares the store, such as an agent,
asks for WasmCompatSend + WasmCompatSync itself. An async store that
is shared is Clone over an inner Arc: Arc<S> is an AsyncStore
only when S is a Store.
Required Methods§
Sourcefn read_log_async(
&self,
name: &str,
) -> impl Future<Output = Result<Vec<u8>>> + WasmCompatSend
fn read_log_async( &self, name: &str, ) -> impl Future<Output = Result<Vec<u8>>> + WasmCompatSend
The whole log name.
Sourcefn append_log_async(
&self,
name: &str,
len: u64,
bytes: &[u8],
) -> impl Future<Output = Result<(), LogWriteError>> + WasmCompatSend
fn append_log_async( &self, name: &str, len: u64, bytes: &[u8], ) -> impl Future<Output = Result<(), LogWriteError>> + WasmCompatSend
Appends bytes to the log name if it is len bytes long now
(Store::append_log).
Sourcefn replace_log_async(
&self,
name: &str,
len: u64,
bytes: &[u8],
) -> impl Future<Output = Result<(), LogWriteError>> + WasmCompatSend
fn replace_log_async( &self, name: &str, len: u64, bytes: &[u8], ) -> impl Future<Output = Result<(), LogWriteError>> + WasmCompatSend
Replaces the log name with bytes if it is len bytes long now,
atomically and durably (Store::replace_log).
Sourcefn read_file_async(
&self,
name: &str,
) -> impl Future<Output = Result<Vec<u8>>> + WasmCompatSend
fn read_file_async( &self, name: &str, ) -> impl Future<Output = Result<Vec<u8>>> + WasmCompatSend
The file name.
Sourcefn write_file_async(
&self,
name: &str,
bytes: &[u8],
) -> impl Future<Output = Result<()>> + WasmCompatSend
fn write_file_async( &self, name: &str, bytes: &[u8], ) -> impl Future<Output = Result<()>> + WasmCompatSend
Replaces the file name with bytes, atomically.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl<S: Store + ?Sized> AsyncStore for S
A local store’s calls, done when made.