pub trait RustType<Proto>: Sized {
fn into_proto(&self) -> Proto;
fn from_proto(proto: Proto) -> Result<Self, TryFromProtoError>;
}
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
fn into_proto(&self) -> Proto
fn into_proto(&self) -> Proto
Convert a Self
into a Proto
value.
fn 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
.
Implementations on Foreign Types
sourceimpl RustType<ProtoOptionalNumericMaxScale> for Option<NumericMaxScale>
impl RustType<ProtoOptionalNumericMaxScale> for Option<NumericMaxScale>
fn into_proto(&self) -> ProtoOptionalNumericMaxScale
fn from_proto(
max_scale: ProtoOptionalNumericMaxScale
) -> Result<Self, TryFromProtoError>
sourceimpl RustType<String> for Regex
impl RustType<String> for Regex
fn into_proto(&self) -> String
fn from_proto(proto: String) -> Result<Self, TryFromProtoError>
sourceimpl RustType<ProtoNaiveDate> for NaiveDate
impl RustType<ProtoNaiveDate> for NaiveDate
fn into_proto(&self) -> ProtoNaiveDate
fn from_proto(proto: ProtoNaiveDate) -> Result<Self, TryFromProtoError>
sourceimpl RustType<ProtoNaiveTime> for NaiveTime
impl RustType<ProtoNaiveTime> for NaiveTime
fn into_proto(&self) -> ProtoNaiveTime
fn from_proto(proto: ProtoNaiveTime) -> Result<Self, TryFromProtoError>
sourceimpl RustType<ProtoNaiveDateTime> for NaiveDateTime
impl RustType<ProtoNaiveDateTime> for NaiveDateTime
fn into_proto(&self) -> ProtoNaiveDateTime
fn from_proto(proto: ProtoNaiveDateTime) -> Result<Self, TryFromProtoError>
sourceimpl RustType<ProtoNaiveDateTime> for DateTime<Utc>
impl RustType<ProtoNaiveDateTime> for DateTime<Utc>
fn into_proto(&self) -> ProtoNaiveDateTime
fn from_proto(proto: ProtoNaiveDateTime) -> Result<Self, TryFromProtoError>
sourceimpl RustType<ProtoFixedOffset> for FixedOffset
impl RustType<ProtoFixedOffset> for FixedOffset
fn into_proto(&self) -> ProtoFixedOffset
fn from_proto(proto: ProtoFixedOffset) -> Result<Self, TryFromProtoError>
sourceimpl RustType<ProtoTz> for Tz
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>
sourceimpl<K, V, T> RustType<Vec<T, Global>> for HashMap<K, V> where
K: Eq + Hash,
T: ProtoMapEntry<K, V>,
impl<K, V, T> RustType<Vec<T, Global>> for HashMap<K, V> where
K: Eq + Hash,
T: ProtoMapEntry<K, V>,
Blanket implementation for HashMap<K, V>
where there exists T
such
that T
implements ProtoMapEntry<K, V>
.
fn into_proto(&self) -> Vec<T>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
fn from_proto(proto: Vec<T>) -> Result<Self, TryFromProtoError>
sourceimpl RustType<bool> for bool
impl RustType<bool> for bool
Identity type for $t.
fn into_proto(&self) -> bool
fn from_proto(proto: bool) -> Result<Self, TryFromProtoError>
sourceimpl RustType<f32> for f32
impl RustType<f32> for f32
Identity type for $t.
fn into_proto(&self) -> f32
fn from_proto(proto: f32) -> Result<Self, TryFromProtoError>
sourceimpl RustType<f64> for f64
impl RustType<f64> for f64
Identity type for $t.
fn into_proto(&self) -> f64
fn from_proto(proto: f64) -> Result<Self, TryFromProtoError>
sourceimpl RustType<i32> for i32
impl RustType<i32> for i32
Identity type for $t.
fn into_proto(&self) -> i32
fn from_proto(proto: i32) -> Result<Self, TryFromProtoError>
sourceimpl RustType<i64> for i64
impl RustType<i64> for i64
Identity type for $t.
fn into_proto(&self) -> i64
fn from_proto(proto: i64) -> Result<Self, TryFromProtoError>
sourceimpl RustType<String> for String
impl RustType<String> for String
Identity type for $t.
fn into_proto(&self) -> String
fn from_proto(proto: String) -> Result<Self, TryFromProtoError>
sourceimpl RustType<u32> for u32
impl RustType<u32> for u32
Identity type for $t.
fn into_proto(&self) -> u32
fn from_proto(proto: u32) -> Result<Self, TryFromProtoError>
sourceimpl RustType<u64> for u64
impl RustType<u64> for u64
Identity type for $t.
fn into_proto(&self) -> u64
fn from_proto(proto: u64) -> Result<Self, TryFromProtoError>
sourceimpl<K, V, T> RustType<Vec<T, Global>> for BTreeMap<K, V> where
K: Eq + Ord,
T: ProtoMapEntry<K, V>,
impl<K, V, T> RustType<Vec<T, Global>> for BTreeMap<K, V> where
K: Eq + Ord,
T: ProtoMapEntry<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>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
fn from_proto(proto: Vec<T>) -> Result<Self, TryFromProtoError>
sourceimpl<R, P> RustType<Vec<P, Global>> for BTreeSet<R> where
R: RustType<P> + Ord,
impl<R, P> RustType<Vec<P, Global>> for BTreeSet<R> where
R: RustType<P> + Ord,
Blanket implementation for BTreeSet<R>
where R
is a RustType
.
fn into_proto(&self) -> Vec<P>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
fn from_proto(proto: Vec<P>) -> Result<Self, TryFromProtoError>
sourceimpl<R, P> RustType<Vec<P, Global>> for Vec<R> where
R: RustType<P>,
impl<R, P> RustType<Vec<P, Global>> for Vec<R> where
R: RustType<P>,
Blanket implementation for Vec<R>
where R
is a RustType
.
fn into_proto(&self) -> Vec<P>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
fn from_proto(proto: Vec<P>) -> Result<Self, TryFromProtoError>
sourceimpl<R, P> RustType<Option<P>> for Option<R> where
R: RustType<P>,
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>
sourceimpl<R, P> RustType<Box<P, Global>> for Box<R> where
R: RustType<P>,
impl<R, P> RustType<Box<P, Global>> for Box<R> where
R: RustType<P>,
Blanket implementation for Box<R>
where R
is a RustType
.