mz_proto

Trait RustType

Source
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§

Source

fn into_proto(&self) -> Proto

Convert a Self into a Proto value.

Source

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§

Source

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", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl RustType<bool> for bool

Identity type for $t.

Source§

impl RustType<f32> for f32

Identity type for $t.

Source§

impl RustType<f64> for f64

Identity type for $t.

Source§

impl RustType<i32> for i8

Source§

impl RustType<i32> for i16

Source§

impl RustType<i32> for i32

Identity type for $t.

Source§

impl RustType<i64> for i64

Identity type for $t.

Source§

impl RustType<u32> for char

Source§

impl RustType<u32> for u8

Source§

impl RustType<u32> for u16

Source§

impl RustType<u32> for u32

Identity type for $t.

Source§

impl RustType<u64> for Option<NonZeroU64>

Source§

impl RustType<u64> for u64

Identity type for $t.

Source§

impl RustType<u64> for usize

Source§

impl RustType<u64> for NonZeroUsize

Source§

impl RustType<()> for ()

Source§

impl RustType<ProtoFixedOffset> for FixedOffset

Source§

impl RustType<ProtoNaiveDate> for NaiveDate

Source§

impl RustType<ProtoNaiveDateTime> for DateTime<Utc>

Source§

impl RustType<ProtoNaiveDateTime> for NaiveDateTime

Source§

impl RustType<ProtoNaiveTime> for NaiveTime

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).

Source§

impl RustType<String> for Box<str>

Source§

impl RustType<String> for String

Identity type for $t.

Source§

impl RustType<Vec<u8>> for Vec<u8>

Identity type for $t.

Source§

impl RustType<ProtoDuration> for Duration

Source§

impl RustType<ProtoU128> for u128

Source§

impl RustType<ProtoU128> for Uuid

Source§

impl RustType<ProtoSslMode> for SslMode

Source§

impl<'a> RustType<String> for Cow<'a, str>

Source§

impl<K, V, T> RustType<Vec<T>> 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>.

Source§

fn into_proto(&self) -> Vec<T>

Source§

fn from_proto(proto: Vec<T>) -> Result<Self, TryFromProtoError>

Source§

impl<R1, R2, P1, P2> RustType<(P1, P2)> for (R1, R2)
where R1: RustType<P1>, R2: RustType<P2>,

Source§

impl<R, P> RustType<Option<P>> for Option<R>
where R: RustType<P>,

Blanket implementation for Option<R> where R is a RustType.

Source§

impl<R, P> RustType<Box<P>> for Box<R>
where R: RustType<P>,

Blanket implementation for Box<R> where R is a RustType.

Source§

fn into_proto(&self) -> Box<P>

Source§

fn from_proto(proto: Box<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.

Source§

fn into_proto(&self) -> Vec<P>

Source§

fn from_proto(proto: Vec<P>) -> Result<Self, TryFromProtoError>

Source§

impl<R, P> RustType<Vec<P>> for BTreeSet<R>
where R: RustType<P> + Ord,

Blanket implementation for BTreeSet<R> where R is a RustType.

Source§

fn into_proto(&self) -> Vec<P>

Source§

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.

Source§

fn into_proto(&self) -> Vec<P>

Source§

fn from_proto(proto: Vec<P>) -> Result<Self, TryFromProtoError>

Source§

impl<R, P> RustType<P> for Arc<R>
where R: RustType<P>,

Source§

fn into_proto(&self) -> P

Source§

fn from_proto(proto: P) -> Result<Self, TryFromProtoError>

Source§

impl<T> RustType<T> for NonNeg<T>
where T: Clone + Signed + Display,

Source§

fn into_proto(&self) -> T

Source§

fn from_proto(proto: T) -> Result<Self, TryFromProtoError>

Implementors§

impl RustType<SetV1> for SetV1

impl RustType<u64> for LirId

impl RustType<ProtoId> for Id

impl RustType<u64> for SeqNo