pub trait RemoteSerialize: Sized {
// Required methods
fn to_json(&self) -> Option<Value>;
fn from_json(value: &Value) -> Option<Self>;
// Provided methods
fn to_json_vec(&self) -> Option<Vec<u8>> { ... }
fn from_json_slice(bytes: &[u8]) -> Option<Self> { ... }
}Expand description
A record type that can be encoded to / decoded from the JSON wire format.
Blanket-implemented for every T: Serialize + DeserializeOwned, so opting a
record into JSON via with_remote_access() requires no extra boilerplate.
Implement Serialize + Deserialize (e.g. via derive) and the type is
codec-ready.
Required Methods§
Provided Methods§
Sourcefn to_json_vec(&self) -> Option<Vec<u8>>
fn to_json_vec(&self) -> Option<Vec<u8>>
Serialize this value to owned JSON bytes.
The default preserves compatibility with manual implementations by
routing through to_json. The blanket Serde
implementation overrides it with direct T -> Vec<u8> serialization,
avoiding an intermediate serde_json::Value tree.
Sourcefn from_json_slice(bytes: &[u8]) -> Option<Self>
fn from_json_slice(bytes: &[u8]) -> Option<Self>
Deserialize one complete JSON value from bytes.
The default preserves compatibility with manual implementations by
parsing a serde_json::Value and calling
from_json. The blanket Serde implementation
overrides it with direct slice deserialization.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".