pub trait RustType<Proto>: Sized {
// Required methods
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§
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
.
Implementations on Foreign Types§
source§impl RustType<ProtoDuration> for Duration
impl RustType<ProtoDuration> for Duration
fn into_proto(&self) -> ProtoDuration
fn from_proto(proto: ProtoDuration) -> Result<Duration, TryFromProtoError>
source§impl<R, P> RustType<Vec<P, Global>> for BTreeSet<R, Global>where
R: RustType<P> + Ord,
impl<R, P> RustType<Vec<P, Global>> for BTreeSet<R, Global>where R: RustType<P> + Ord,
Blanket implementation for BTreeSet<R>
where R
is a RustType
.
fn into_proto(&self) -> Vec<P, Global>
fn from_proto( proto: Vec<P, Global> ) -> Result<BTreeSet<R, Global>, TryFromProtoError>
source§impl RustType<f32> for f32
impl RustType<f32> for f32
Identity type for $t.
fn into_proto(&self) -> f32
fn from_proto(proto: f32) -> Result<f32, TryFromProtoError>
source§impl RustType<f64> for f64
impl RustType<f64> for f64
Identity type for $t.
fn into_proto(&self) -> f64
fn from_proto(proto: f64) -> Result<f64, TryFromProtoError>
source§impl RustType<String> for String
impl RustType<String> for String
Identity type for $t.
fn into_proto(&self) -> String
fn from_proto(proto: String) -> Result<String, TryFromProtoError>
source§impl RustType<u64> for u64
impl RustType<u64> for u64
Identity type for $t.
fn into_proto(&self) -> u64
fn from_proto(proto: u64) -> Result<u64, TryFromProtoError>
source§impl<K, V, T> RustType<Vec<T, Global>> for BTreeMap<K, V, Global>where
K: Eq + Ord,
T: ProtoMapEntry<K, V>,
impl<K, V, T> RustType<Vec<T, Global>> for BTreeMap<K, V, Global>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, Global>
fn from_proto( proto: Vec<T, Global> ) -> Result<BTreeMap<K, V, Global>, TryFromProtoError>
source§impl RustType<i32> for i8
impl RustType<i32> for i8
fn into_proto(&self) -> i32
fn from_proto(proto: i32) -> Result<i8, TryFromProtoError>
source§impl RustType<i32> for i32
impl RustType<i32> for i32
Identity type for $t.
fn into_proto(&self) -> i32
fn from_proto(proto: i32) -> Result<i32, TryFromProtoError>
source§impl<R, P> RustType<Box<P, Global>> for Box<R, Global>where
R: RustType<P>,
impl<R, P> RustType<Box<P, Global>> for Box<R, Global>where R: RustType<P>,
Blanket implementation for Box<R>
where R
is a RustType
.
fn into_proto(&self) -> Box<P, Global>
fn from_proto( proto: Box<P, Global> ) -> Result<Box<R, Global>, TryFromProtoError>
source§impl RustType<u32> for u16
impl RustType<u32> for u16
fn into_proto(&self) -> u32
fn from_proto(repr: u32) -> Result<u16, TryFromProtoError>
source§impl RustType<ProtoU128> for Uuid
impl RustType<ProtoU128> for Uuid
fn into_proto(&self) -> ProtoU128
fn from_proto(proto: ProtoU128) -> Result<Uuid, TryFromProtoError>
source§impl<R1, R2, P1, P2> RustType<(P1, P2)> for (R1, R2)where
R1: RustType<P1>,
R2: RustType<P2>,
impl<R1, R2, P1, P2> RustType<(P1, P2)> for (R1, R2)where R1: RustType<P1>, R2: RustType<P2>,
fn into_proto(&self) -> (P1, P2)
fn from_proto(proto: (P1, P2)) -> Result<(R1, R2), TryFromProtoError>
source§impl RustType<ProtoSslMode> for SslMode
impl RustType<ProtoSslMode> for SslMode
fn into_proto(&self) -> ProtoSslMode
fn from_proto(proto: ProtoSslMode) -> Result<SslMode, TryFromProtoError>
source§impl RustType<u32> for char
impl RustType<u32> for char
fn into_proto(&self) -> u32
fn from_proto(proto: u32) -> Result<char, 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<Option<NonZeroU64>, TryFromProtoError>
source§impl RustType<i32> for i16
impl RustType<i32> for i16
fn into_proto(&self) -> i32
fn from_proto(repr: i32) -> Result<i16, TryFromProtoError>
source§impl RustType<ProtoU128> for u128
impl RustType<ProtoU128> for u128
fn into_proto(&self) -> ProtoU128
fn from_proto(proto: ProtoU128) -> Result<u128, TryFromProtoError>
source§impl<R, P> RustType<Vec<P, Global>> for Vec<R, Global>where
R: RustType<P>,
impl<R, P> RustType<Vec<P, Global>> for Vec<R, Global>where R: RustType<P>,
Blanket implementation for Vec<R>
where R
is a RustType
.
fn into_proto(&self) -> Vec<P, Global>
fn from_proto( proto: Vec<P, Global> ) -> Result<Vec<R, Global>, TryFromProtoError>
source§impl RustType<u32> for u8
impl RustType<u32> for u8
fn into_proto(&self) -> u32
fn from_proto(proto: u32) -> Result<u8, TryFromProtoError>
source§impl RustType<u64> for NonZeroUsize
impl RustType<u64> for NonZeroUsize
fn into_proto(&self) -> u64
fn from_proto(proto: u64) -> Result<NonZeroUsize, TryFromProtoError>
source§impl RustType<u32> for u32
impl RustType<u32> for u32
Identity type for $t.
fn into_proto(&self) -> u32
fn from_proto(proto: u32) -> Result<u32, TryFromProtoError>
source§impl<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<Option<R>, TryFromProtoError>
source§impl RustType<i64> for i64
impl RustType<i64> for i64
Identity type for $t.
fn into_proto(&self) -> i64
fn from_proto(proto: i64) -> Result<i64, TryFromProtoError>
source§impl RustType<()> for ()
impl RustType<()> for ()
fn into_proto(&self)
fn from_proto(proto: ()) -> Result<(), TryFromProtoError>
source§impl RustType<u64> for usize
impl RustType<u64> for usize
fn into_proto(&self) -> u64
fn from_proto(proto: u64) -> Result<usize, TryFromProtoError>
source§impl RustType<bool> for bool
impl RustType<bool> for bool
Identity type for $t.
fn into_proto(&self) -> bool
fn from_proto(proto: bool) -> Result<bool, TryFromProtoError>
source§impl RustType<ProtoU64Antichain> for Antichain<Timestamp>
impl RustType<ProtoU64Antichain> for Antichain<Timestamp>
fn into_proto(&self) -> ProtoU64Antichain
fn from_proto( proto: ProtoU64Antichain ) -> Result<Antichain<Timestamp>, TryFromProtoError>
source§impl RustType<ProtoCharLength> for CharLength
impl RustType<ProtoCharLength> for CharLength
fn into_proto(&self) -> ProtoCharLength
fn from_proto(proto: ProtoCharLength) -> Result<CharLength, 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<DateTime<Utc>, TryFromProtoError>
source§impl RustType<ProtoVarCharMaxLength> for VarCharMaxLength
impl RustType<ProtoVarCharMaxLength> for VarCharMaxLength
fn into_proto(&self) -> ProtoVarCharMaxLength
fn from_proto( proto: ProtoVarCharMaxLength ) -> Result<VarCharMaxLength, TryFromProtoError>
source§impl RustType<ProtoTimestampPrecision> for TimestampPrecision
impl RustType<ProtoTimestampPrecision> for TimestampPrecision
fn into_proto(&self) -> ProtoTimestampPrecision
fn from_proto( proto: ProtoTimestampPrecision ) -> Result<TimestampPrecision, TryFromProtoError>
source§impl RustType<ProtoOptionalNumericMaxScale> for Option<NumericMaxScale>
impl RustType<ProtoOptionalNumericMaxScale> for Option<NumericMaxScale>
fn into_proto(&self) -> ProtoOptionalNumericMaxScale
fn from_proto( max_scale: ProtoOptionalNumericMaxScale ) -> Result<Option<NumericMaxScale>, TryFromProtoError>
source§impl RustType<ProtoGlobalId> for GlobalId
impl RustType<ProtoGlobalId> for GlobalId
fn into_proto(&self) -> ProtoGlobalId
fn from_proto(proto: ProtoGlobalId) -> Result<GlobalId, TryFromProtoError>
source§impl RustType<ProtoColumnType> for ColumnType
impl RustType<ProtoColumnType> for ColumnType
fn into_proto(&self) -> ProtoColumnType
fn from_proto(proto: ProtoColumnType) -> Result<ColumnType, TryFromProtoError>
source§impl RustType<ProtoRegex> for Regex
impl RustType<ProtoRegex> for Regex
fn into_proto(&self) -> ProtoRegex
fn from_proto(proto: ProtoRegex) -> Result<Regex, TryFromProtoError>
source§impl RustType<ProtoAclMode> for AclMode
impl RustType<ProtoAclMode> for AclMode
fn into_proto(&self) -> ProtoAclMode
fn from_proto(proto: ProtoAclMode) -> Result<AclMode, TryFromProtoError>
source§impl RustType<ProtoNaiveTime> for NaiveTime
impl RustType<ProtoNaiveTime> for NaiveTime
fn into_proto(&self) -> ProtoNaiveTime
fn from_proto(proto: ProtoNaiveTime) -> Result<NaiveTime, TryFromProtoError>
source§impl RustType<ProtoInvalidRangeError> for InvalidRangeError
impl RustType<ProtoInvalidRangeError> for InvalidRangeError
fn into_proto(&self) -> ProtoInvalidRangeError
fn from_proto( proto: ProtoInvalidRangeError ) -> Result<InvalidRangeError, TryFromProtoError>
source§impl RustType<ProtoAclItem> for AclItem
impl RustType<ProtoAclItem> for AclItem
fn into_proto(&self) -> ProtoAclItem
fn from_proto(proto: ProtoAclItem) -> Result<AclItem, TryFromProtoError>
source§impl RustType<ProtoRoleId> for RoleId
impl RustType<ProtoRoleId> for RoleId
fn into_proto(&self) -> ProtoRoleId
fn from_proto(proto: ProtoRoleId) -> Result<RoleId, TryFromProtoError>
source§impl RustType<ProtoRow> for Row
impl RustType<ProtoRow> for Row
fn into_proto(&self) -> ProtoRow
fn from_proto(proto: ProtoRow) -> Result<Row, TryFromProtoError>
source§impl 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).