pub struct ProxyDef {
pub shape: &'static Shape,
pub convert_in: ProxyConvertInFn,
pub convert_out: ProxyConvertOutFn,
}Expand description
Definition of a proxy type for custom serialization/deserialization.
A ProxyDef specifies how to convert between a target type and a proxy type.
This can be used at both the container level (on a struct/enum) and the field level.
§Container-level proxy
When applied to a struct or enum with #[facet(proxy = ProxyType)]:
- Serialization: target → proxy via
convert_out - Deserialization: proxy → target via
convert_in
§Field-level proxy
When applied to a field with #[facet(proxy = ProxyType)]:
- The field is serialized/deserialized through the proxy type
- Requires
TryFrom<ProxyType> for FieldTypeandTryFrom<&FieldType> for ProxyType
§Example (generated by derive macro)
ⓘ
ProxyDef {
shape: <ProxyType as Facet>::SHAPE,
convert_in: Self::__facet_proxy_convert_in,
convert_out: Self::__facet_proxy_convert_out,
}Fields§
§shape: &'static ShapeThe shape of the proxy type.
convert_in: ProxyConvertInFnConverts from proxy type to target type (deserialization).
Called when deserializing: first deserialize into proxy, then convert to target.
convert_out: ProxyConvertOutFnConverts from target type to proxy type (serialization).
Called when serializing: convert target to proxy, then serialize proxy.
Trait Implementations§
impl Copy for ProxyDef
Auto Trait Implementations§
impl Freeze for ProxyDef
impl RefUnwindSafe for ProxyDef
impl Send for ProxyDef
impl Sync for ProxyDef
impl Unpin for ProxyDef
impl UnwindSafe for ProxyDef
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more