pub trait RustType<Proto>: Sized {
// Required methods
fn into_proto(&self) -> Proto;
fn from_proto(proto: Proto) -> Result<Self, TryFromProtoError>;
// Provided method
fn into_proto_owned(self) -> Proto { ... }
}Expand description
A trait for representing a Rust type Self as a value of
type Proto for the purpose of serializing this
value as (part of) a Protobuf message.
To encode a value, use RustType::into_proto() (which
should always be an infallible conversion).
To decode a value, use the fallible RustType::from_proto().
Since the representation type can be “bigger” than the original,
decoding may fail, indicated by returning a TryFromProtoError
wrapped in a Result::Err.
Convenience syntax for the above methods is available from the
matching ProtoType.
Required Methods§
Sourcefn into_proto(&self) -> Proto
fn into_proto(&self) -> Proto
Convert a Self into a Proto value.
Sourcefn from_proto(proto: Proto) -> Result<Self, TryFromProtoError>
fn from_proto(proto: Proto) -> Result<Self, TryFromProtoError>
Consume and convert a Proto back into a Self value.
Since Proto can be “bigger” than the original, this
may fail, indicated by returning a TryFromProtoError
wrapped in a Result::Err.
Provided Methods§
Sourcefn into_proto_owned(self) -> Proto
fn into_proto_owned(self) -> Proto
A zero clone version of Self::into_proto that types can
optionally implement, otherwise, the default implementation
delegates to Self::into_proto.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl RustType<()> for ()
impl RustType<()> for ()
fn into_proto(&self)
fn from_proto(proto: ()) -> Result<Self, TryFromProtoError>
Source§impl RustType<ProtoDuration> for Duration
impl RustType<ProtoDuration> for Duration
fn into_proto(&self) -> ProtoDuration
fn from_proto(proto: ProtoDuration) -> Result<Self, TryFromProtoError>
Source§impl RustType<ProtoFixedOffset> for FixedOffset
impl RustType<ProtoFixedOffset> for FixedOffset
fn into_proto(&self) -> ProtoFixedOffset
fn from_proto(proto: ProtoFixedOffset) -> Result<Self, TryFromProtoError>
Source§impl RustType<ProtoNaiveDateTime> for DateTime<Utc>
impl RustType<ProtoNaiveDateTime> for DateTime<Utc>
fn into_proto(&self) -> ProtoNaiveDateTime
fn from_proto(proto: ProtoNaiveDateTime) -> Result<Self, TryFromProtoError>
Source§impl RustType<ProtoNaiveDateTime> for NaiveDateTime
impl RustType<ProtoNaiveDateTime> for NaiveDateTime
fn into_proto(&self) -> ProtoNaiveDateTime
fn from_proto(proto: ProtoNaiveDateTime) -> Result<Self, TryFromProtoError>
Source§impl RustType<ProtoNaiveTime> for NaiveTime
impl RustType<ProtoNaiveTime> for NaiveTime
fn into_proto(&self) -> ProtoNaiveTime
fn from_proto(proto: ProtoNaiveTime) -> Result<Self, TryFromProtoError>
Source§impl RustType<ProtoTz> for Tz
Encode a Tz as string representation. This is not the most space efficient solution, but
it is immune to changes in the chrono_tz (and is fully compatible with its public API).
impl RustType<ProtoTz> for Tz
Encode a Tz as string representation. This is not the most space efficient solution, but it is immune to changes in the chrono_tz (and is fully compatible with its public API).
fn into_proto(&self) -> ProtoTz
fn from_proto(proto: ProtoTz) -> Result<Self, TryFromProtoError>
Source§impl RustType<String> for Box<str>
impl RustType<String> for Box<str>
fn into_proto(&self) -> String
fn from_proto(proto: String) -> Result<Self, TryFromProtoError>
Source§impl RustType<String> for String
Identity type for $t.
impl RustType<String> for String
Identity type for $t.
fn into_proto(&self) -> String
fn from_proto(proto: String) -> Result<Self, TryFromProtoError>
Source§impl RustType<Vec<u8>> for Vec<u8>
Identity type for $t.
impl RustType<Vec<u8>> for Vec<u8>
Identity type for $t.
fn into_proto(&self) -> Vec<u8> ⓘ
fn from_proto(proto: Vec<u8>) -> Result<Self, TryFromProtoError>
Source§impl RustType<bool> for bool
Identity type for $t.
impl RustType<bool> for bool
Identity type for $t.
fn into_proto(&self) -> bool
fn from_proto(proto: bool) -> Result<Self, TryFromProtoError>
Source§impl RustType<f32> for f32
Identity type for $t.
impl RustType<f32> for f32
Identity type for $t.
fn into_proto(&self) -> f32
fn from_proto(proto: f32) -> Result<Self, TryFromProtoError>
Source§impl RustType<f64> for f64
Identity type for $t.
impl RustType<f64> for f64
Identity type for $t.
fn into_proto(&self) -> f64
fn from_proto(proto: f64) -> Result<Self, TryFromProtoError>
Source§impl RustType<i32> for i8
impl RustType<i32> for i8
fn into_proto(&self) -> i32
fn from_proto(proto: i32) -> Result<Self, TryFromProtoError>
Source§impl RustType<i32> for i16
impl RustType<i32> for i16
fn into_proto(&self) -> i32
fn from_proto(repr: i32) -> Result<Self, TryFromProtoError>
Source§impl RustType<i32> for i32
Identity type for $t.
impl RustType<i32> for i32
Identity type for $t.
fn into_proto(&self) -> i32
fn from_proto(proto: i32) -> Result<Self, TryFromProtoError>
Source§impl RustType<i64> for Overflowing<i64>
impl RustType<i64> for Overflowing<i64>
fn into_proto(&self) -> i64
fn from_proto(proto: i64) -> Result<Self, TryFromProtoError>
Source§impl RustType<i64> for i64
Identity type for $t.
impl RustType<i64> for i64
Identity type for $t.
fn into_proto(&self) -> i64
fn from_proto(proto: i64) -> Result<Self, TryFromProtoError>
Source§impl RustType<u32> for char
impl RustType<u32> for char
fn into_proto(&self) -> u32
fn from_proto(proto: u32) -> Result<Self, TryFromProtoError>
Source§impl RustType<u32> for u8
impl RustType<u32> for u8
fn into_proto(&self) -> u32
fn from_proto(proto: u32) -> Result<Self, TryFromProtoError>
Source§impl RustType<u32> for u16
impl RustType<u32> for u16
fn into_proto(&self) -> u32
fn from_proto(repr: u32) -> Result<Self, TryFromProtoError>
Source§impl RustType<u32> for u32
Identity type for $t.
impl RustType<u32> for u32
Identity type for $t.
fn into_proto(&self) -> u32
fn from_proto(proto: u32) -> Result<Self, TryFromProtoError>
Source§impl RustType<u64> for NonZeroUsize
impl RustType<u64> for NonZeroUsize
fn into_proto(&self) -> u64
fn from_proto(proto: u64) -> Result<Self, TryFromProtoError>
Source§impl RustType<u64> for Option<NonZeroU64>
impl RustType<u64> for Option<NonZeroU64>
fn into_proto(&self) -> u64
fn from_proto(proto: u64) -> Result<Self, TryFromProtoError>
Source§impl RustType<u64> for u64
Identity type for $t.
impl RustType<u64> for u64
Identity type for $t.
fn into_proto(&self) -> u64
fn from_proto(proto: u64) -> Result<Self, TryFromProtoError>
Source§impl RustType<u64> for usize
impl RustType<u64> for usize
fn into_proto(&self) -> u64
fn from_proto(proto: u64) -> Result<Self, TryFromProtoError>
Source§impl<'a> RustType<String> for Cow<'a, str>
impl<'a> RustType<String> for Cow<'a, str>
fn into_proto(&self) -> String
fn from_proto(proto: String) -> Result<Self, TryFromProtoError>
Source§impl<K, V, T> RustType<Vec<T>> for BTreeMap<K, V>
Blanket implementation for BTreeMap<K, V> where there exists T such
that T implements ProtoMapEntry<K, V>.
impl<K, V, T> RustType<Vec<T>> for BTreeMap<K, V>
Blanket implementation for BTreeMap<K, V> where there exists T such
that T implements ProtoMapEntry<K, V>.
fn into_proto(&self) -> Vec<T>
fn from_proto(proto: Vec<T>) -> Result<Self, TryFromProtoError>
Source§impl<R1, R2, P1, P2> RustType<(P1, P2)> for (R1, R2)
impl<R1, R2, P1, P2> RustType<(P1, P2)> for (R1, R2)
fn into_proto(&self) -> (P1, P2)
fn from_proto(proto: (P1, P2)) -> Result<Self, TryFromProtoError>
Source§impl<R, P> RustType<Box<P>> for Box<R>where
R: RustType<P>,
Blanket implementation for Box<R> where R is a RustType.
impl<R, P> RustType<Box<P>> for Box<R>where
R: RustType<P>,
Blanket implementation for Box<R> where R is a RustType.
fn into_proto(&self) -> Box<P>
fn from_proto(proto: Box<P>) -> Result<Self, TryFromProtoError>
Source§impl<R, P> RustType<Option<P>> for Option<R>where
R: RustType<P>,
Blanket implementation for Option<R> where R is a RustType.
impl<R, P> RustType<Option<P>> for Option<R>where
R: RustType<P>,
Blanket implementation for Option<R> where R is a RustType.
fn into_proto(&self) -> Option<P>
fn from_proto(proto: Option<P>) -> Result<Self, TryFromProtoError>
Source§impl<R, P> RustType<P> for Arc<R>where
R: RustType<P>,
impl<R, P> RustType<P> for Arc<R>where
R: RustType<P>,
fn into_proto(&self) -> P
fn from_proto(proto: P) -> Result<Self, TryFromProtoError>
Source§impl<R, P> RustType<Vec<P>> for BTreeSet<R>
Blanket implementation for BTreeSet<R> where R is a RustType.
impl<R, P> RustType<Vec<P>> for BTreeSet<R>
Blanket implementation for BTreeSet<R> where R is a RustType.
fn into_proto(&self) -> Vec<P>
fn from_proto(proto: Vec<P>) -> Result<Self, TryFromProtoError>
Source§impl<R, P> RustType<Vec<P>> for Box<[R]>where
R: RustType<P>,
Blanket implementation for Box<[R]> where R is a RustType.
impl<R, P> RustType<Vec<P>> for Box<[R]>where
R: RustType<P>,
Blanket implementation for Box<[R]> where R is a RustType.
fn into_proto(&self) -> Vec<P>
fn from_proto(proto: Vec<P>) -> Result<Self, TryFromProtoError>
Source§impl<R, P> RustType<Vec<P>> for Vec<R>where
R: RustType<P>,
Blanket implementation for Vec<R> where R is a RustType.
impl<R, P> RustType<Vec<P>> for Vec<R>where
R: RustType<P>,
Blanket implementation for Vec<R> where R is a RustType.