pub trait SaSerializer: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn kind(&self, raw: &str) -> ValueKind;
fn encode<T>(&self, value: &T) -> Result<String, SerializerError>
where T: Serialize + ?Sized;
fn decode<T>(&self, raw: &str) -> Result<T, SerializerError>
where T: DeserializeOwned;
// Provided methods
fn encode_bytes<T>(&self, value: &T) -> Result<Vec<u8>, SerializerError>
where T: Serialize + ?Sized { ... }
fn decode_bytes<T>(&self, bytes: &[u8]) -> Result<T, SerializerError>
where T: DeserializeOwned { ... }
}Expand description
Pluggable serializer: domain object ↔ storage string | 可插拔序列化器:领域对象 ↔ 存储字符串
§Methods | 方法
name/kind/encode/decode— core String path | 核心 String 路径encode_bytes/decode_bytes— optional zero-copy path (A2-3) | 可选零拷贝路径
Required Methods§
Sourcefn kind(&self, raw: &str) -> ValueKind
fn kind(&self, raw: &str) -> ValueKind
Detect payload format for rolling upgrades | 探测 payload 格式以支持滚动升级
Sourcefn encode<T>(&self, value: &T) -> Result<String, SerializerError>
fn encode<T>(&self, value: &T) -> Result<String, SerializerError>
Encode domain object to storage string | 编码领域对象为存储字符串
Errors: EncodeFailed on serde failure | 错误:serde 失败时 EncodeFailed
Sourcefn decode<T>(&self, raw: &str) -> Result<T, SerializerError>where
T: DeserializeOwned,
fn decode<T>(&self, raw: &str) -> Result<T, SerializerError>where
T: DeserializeOwned,
Decode storage string to domain object | 解码存储字符串为领域对象
Errors: DecodeFailed / FormatMismatch | 错误:DecodeFailed / FormatMismatch
Provided Methods§
Sourcefn encode_bytes<T>(&self, value: &T) -> Result<Vec<u8>, SerializerError>
fn encode_bytes<T>(&self, value: &T) -> Result<Vec<u8>, SerializerError>
Encode to bytes (default: UTF-8 of encode) | 编码为 bytes(默认委托 encode)
Sourcefn decode_bytes<T>(&self, bytes: &[u8]) -> Result<T, SerializerError>where
T: DeserializeOwned,
fn decode_bytes<T>(&self, bytes: &[u8]) -> Result<T, SerializerError>where
T: DeserializeOwned,
Decode from bytes (default: UTF-8 then decode) | 从 bytes 解码(默认 UTF-8 再 decode)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".