Trait mz_proto::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.

Object Safety§

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§