Trait Backend

Source
pub trait Backend<K> {
    // Required methods
    fn save<F: Format, T: Serialize + ConditionalSend + Sync>(
        &self,
        key: K,
        value: &T,
    ) -> impl ConditionalSendFuture<Output = Result<(), Error>>;
    fn load<F: Format, S: for<'de> DeserializeSeed<'de, Value = T> + ConditionalSend, T>(
        &self,
        key: K,
        seed: S,
    ) -> impl ConditionalSendFuture<Output = Result<T, Error>>;
}
Expand description

Interface between the Format and the disk or other storage.

§Implementation

The preferred style for implementing this method is an async fn returning a result.

impl<K: Send> Backend<K> for ExampleBackend {
    async fn save<F: Format, T: Serialize + ConditionalSend + Sync>(
        &self,
        key: K,
        value: &T
    ) -> Result<(), Error> {
        // ...
    }

    async fn load<F: Format, S: for<'de> DeserializeSeed<'de, Value = T> + ConditionalSend, T>(
        &self,
        key: K,
        seed: S,
    ) -> Result<T, Error> {
        // ...
    }
}

Required Methods§

Source

fn save<F: Format, T: Serialize + ConditionalSend + Sync>( &self, key: K, value: &T, ) -> impl ConditionalSendFuture<Output = Result<(), Error>>

Attempts to serialize a value with the given Format.

§Errors
Source

fn load<F: Format, S: for<'de> DeserializeSeed<'de, Value = T> + ConditionalSend, T>( &self, key: K, seed: S, ) -> impl ConditionalSendFuture<Output = Result<T, Error>>

Attempts to deserialize a value with the given Format.

§Errors

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<K: Display + Send> Backend<K> for FileIO

Available on non-WebAssembly only.