Skip to main content

JsonSerializable

Trait JsonSerializable 

Source
pub trait JsonSerializable<E>: Serialize + for<'de> DeserializeOwned {
    // Required methods
    fn to_json_string(&self) -> Result<String, E>;
    fn from_json_str(s: &str) -> Result<Self, E>;
}
Expand description

Trait for types that can be serialized to/from JSON strings with specific error handling.

This provides a consistent interface for JSON operations throughout the framework. Unlike the other utilities in this module which work with JsonError, this trait is generic over the error type to allow different modules to use their own error types.

Required Methods§

Source

fn to_json_string(&self) -> Result<String, E>

Serialize this object to a JSON string.

§Errors

Returns an error if serialization fails.

Source

fn from_json_str(s: &str) -> Result<Self, E>

Deserialize an object from a JSON string.

§Errors

Returns an error if deserialization fails.

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<T> JsonSerializable<PersistenceError> for T
where T: Serialize + for<'de> DeserializeOwned,

Blanket implementation of JsonSerializable for all suitable types using PersistenceError.