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§
Sourcefn save<F: Format, T: Serialize + ConditionalSend + Sync>(
&self,
key: K,
value: &T,
) -> impl ConditionalSendFuture<Output = Result<(), Error>>
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
Error::Saving
if serialization of the type failsError::IO
if there is an IO or filesystem failure- See
Error
Sourcefn load<F: Format, S: for<'de> DeserializeSeed<'de, Value = T> + ConditionalSend, T>(
&self,
key: K,
seed: S,
) -> impl ConditionalSendFuture<Output = Result<T, 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>>
Attempts to deserialize a value with the given Format
.
§Errors
Error::Loading
if deserialization of the type failsError::IO
if there is an IO or filesystem failure- See
Error
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.