pub trait TypedWriter: Writer {
// Provided methods
fn write_as<T: Serialize>(
&mut self,
to: &Path,
data: &T,
) -> Result<Path, Error> { ... }
fn write_json(&mut self, to: &Path, data: Value) -> Result<Path, Error> { ... }
fn write_typed<T: Serialize>(
&mut self,
to: &Path,
data: &T,
) -> Result<Path, Error> { ... }
}Expand description
Extension trait for typed writes.
This trait is automatically implemented for all Writer implementations.
It provides convenience methods for writing Rust types directly.
§Example
ⓘ
use structfs_serde_store::TypedWriter;
use serde::Serialize;
#[derive(Serialize)]
struct User {
name: String,
email: String,
}
fn create_user(store: &mut dyn Writer, user: &User) -> Result<Path, Error> {
store.write_as(&path!("users/new"), user)
}Provided Methods§
Sourcefn write_as<T: Serialize>(&mut self, to: &Path, data: &T) -> Result<Path, Error>
fn write_as<T: Serialize>(&mut self, to: &Path, data: &T) -> Result<Path, Error>
Serialize a Rust type and write it to the store.
This method:
- Serializes the data to a Value
- Wraps it in a Record::Parsed
- Writes it to the store
Sourcefn write_json(&mut self, to: &Path, data: Value) -> Result<Path, Error>
fn write_json(&mut self, to: &Path, data: Value) -> Result<Path, Error>
Write a serde_json::Value to the store.
Convenience method for dynamic JSON data.
Sourcefn write_typed<T: Serialize>(
&mut self,
to: &Path,
data: &T,
) -> Result<Path, Error>
fn write_typed<T: Serialize>( &mut self, to: &Path, data: &T, ) -> Result<Path, Error>
Codec-free typed write — the mirror of TypedReader::read_typed.
Identical to TypedWriter::write_as; provided so read/write call
sites pair up by name.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".