pub trait ThriftAdapter {
type StandardType;
type AdaptedType: Clone + Debug + PartialEq + Send + Sync;
type Error: Into<Error> + Debug;
// Required methods
fn from_thrift(
value: Self::StandardType,
) -> Result<Self::AdaptedType, Self::Error>;
fn to_thrift(value: &Self::AdaptedType) -> Self::StandardType;
// Provided methods
fn from_thrift_field<T: ThriftAnnotations>(
value: Self::StandardType,
_field_id: i16,
) -> Result<Self::AdaptedType, Self::Error> { ... }
fn to_thrift_field<T: ThriftAnnotations>(
value: &Self::AdaptedType,
_field_id: i16,
) -> Self::StandardType { ... }
fn from_thrift_default<T: ThriftAnnotations>(
value: Self::StandardType,
field_id: i16,
) -> Self::AdaptedType { ... }
}Required Associated Types§
Sourcetype StandardType
type StandardType
Aka the “from” type.
Required Methods§
Sourcefn from_thrift(
value: Self::StandardType,
) -> Result<Self::AdaptedType, Self::Error>
fn from_thrift( value: Self::StandardType, ) -> Result<Self::AdaptedType, Self::Error>
Converts an instance of StandardType to AdaptedType during deserialization.
The Err returned by this method will be propagated as a deserialization error.
Sourcefn to_thrift(value: &Self::AdaptedType) -> Self::StandardType
fn to_thrift(value: &Self::AdaptedType) -> Self::StandardType
Converts from the given AdaptedType back to the given StandardType during
serialization.
This must be an infallible operation as serialize is infallible.
WARNING: you should be particularly cautious when using .unwrap() or any other panic-able
methods in this method. If this method panics, it will be at serialization time and not at
the Thrift struct creation time, meaning it will be extremely difficult to debug what the
true “source” of the panic.
If your AdaptedType -> StandardType conversion is truly fallible, you probably shouldn’t
use an adapter to begin with.
Provided Methods§
Sourcefn from_thrift_field<T: ThriftAnnotations>(
value: Self::StandardType,
_field_id: i16,
) -> Result<Self::AdaptedType, Self::Error>
fn from_thrift_field<T: ThriftAnnotations>( value: Self::StandardType, _field_id: i16, ) -> Result<Self::AdaptedType, Self::Error>
Method called when this adapter is used on a Thrift struct’s field. Provides information
about the specific field ID in field_id. The type of the struct that owns this field is
passed in as T.
Defaults to calling from_thrift.
Sourcefn to_thrift_field<T: ThriftAnnotations>(
value: &Self::AdaptedType,
_field_id: i16,
) -> Self::StandardType
fn to_thrift_field<T: ThriftAnnotations>( value: &Self::AdaptedType, _field_id: i16, ) -> Self::StandardType
Method called when this adapter is used on a Thrift struct’s field. Provides information
about the specific field ID in field_id. The type of the struct that owns this field is
passed in as T.
Defaults to calling to_thrift.
Sourcefn from_thrift_default<T: ThriftAnnotations>(
value: Self::StandardType,
field_id: i16,
) -> Self::AdaptedType
fn from_thrift_default<T: ThriftAnnotations>( value: Self::StandardType, field_id: i16, ) -> Self::AdaptedType
Method called when the adapted type is not present in a field during deserialization or is
populated with ..Default::default(). The value passed here is the default original type
value for the field. This can be used to record that the field was not present inside
of your adapted type.
This method must be infallible, as it will be called when Default::default() is used
(which is infallible).
WARNING: This defaults to calling from_thrift_field and assumes from_thrift_field
will not return an Err for the default value.
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.