pub trait ProtoCodec<T, R> {
Show 19 methods
// Required methods
fn encode(value: &T) -> R;
fn decode(value: &R) -> Result<T>;
// Provided methods
fn encode_some(value: &T) -> Option<R> { ... }
fn encode_enum(value: &T) -> i32
where R: Into<i32> { ... }
fn encode_vec<'a, I>(values: I) -> Vec<R>
where I: IntoIterator<Item = &'a T>,
T: 'a { ... }
fn decode_wrap(value: &R, msg: &'static str) -> Result<T> { ... }
fn decode_vec(values: &[R]) -> Result<Vec<T>> { ... }
fn decode_vec_wrap(values: &[R], msg: &'static str) -> Result<Vec<T>> { ... }
fn decode_arr<const N: usize>(values: &[R]) -> Result<[T; N]> { ... }
fn decode_arr_wrap<const N: usize>(
values: &[R],
msg: &'static str,
) -> Result<[T; N]> { ... }
fn decode_box_arr<const N: usize>(values: &[R]) -> Result<Box<[T; N]>> { ... }
fn decode_box_arr_wrap<const N: usize>(
values: &[R],
msg: &'static str,
) -> Result<Box<[T; N]>> { ... }
fn decode_some(value: &Option<R>) -> Result<T> { ... }
fn decode_some_wrap(value: &Option<R>, msg: &'static str) -> Result<T> { ... }
fn decode_opt_wrap(
value: &Option<R>,
msg: &'static str,
) -> Result<Option<T>> { ... }
fn decode_enum(value: i32) -> Result<T>
where R: TryFrom<i32, Error = UnknownEnumValue> { ... }
fn decode_enum_wrap(value: i32, msg: &'static str) -> Result<T>
where R: TryFrom<i32, Error = UnknownEnumValue> { ... }
fn serialize_to_vec(value: &T) -> Vec<u8> ⓘ
where R: Message { ... }
fn deserialize_from_slice(buf: &[u8]) -> Result<T>
where R: Message + Default { ... }
}
Expand description
A protobuf codec to convert between a domain type T
and its protobuf representation R
.
It is to be implemented on a Self
independent of T
and R
,
so that T
can be in a third party crate, and Self
can be
generic in the F
field type as well, which would be cumbersome
if we had to implement traits on R
because T
is in another
crate from the schema, or to scatter the .proto
schema around
so that the traits can be co-defined with T
which is what can
actually be generic in F
.
Required Methods§
Provided Methods§
Sourcefn encode_some(value: &T) -> Option<R>
fn encode_some(value: &T) -> Option<R>
Encode a field as Some
.
Sourcefn encode_enum(value: &T) -> i32
fn encode_enum(value: &T) -> i32
Encode an enum
to the i32
value that prost
represents it with.
Sourcefn encode_vec<'a, I>(values: I) -> Vec<R>where
I: IntoIterator<Item = &'a T>,
T: 'a,
fn encode_vec<'a, I>(values: I) -> Vec<R>where
I: IntoIterator<Item = &'a T>,
T: 'a,
Encode multiple values as a vector.
Sourcefn decode_wrap(value: &R, msg: &'static str) -> Result<T>
fn decode_wrap(value: &R, msg: &'static str) -> Result<T>
Decode a field and attach the name of the field if it fails.
Sourcefn decode_vec(values: &[R]) -> Result<Vec<T>>
fn decode_vec(values: &[R]) -> Result<Vec<T>>
Decode multiple values into a vector.
Sourcefn decode_vec_wrap(values: &[R], msg: &'static str) -> Result<Vec<T>>
fn decode_vec_wrap(values: &[R], msg: &'static str) -> Result<Vec<T>>
Decode multiple values into a vector, attaching a field name to any errors.
Sourcefn decode_arr_wrap<const N: usize>(
values: &[R],
msg: &'static str,
) -> Result<[T; N]>
fn decode_arr_wrap<const N: usize>( values: &[R], msg: &'static str, ) -> Result<[T; N]>
Decode a fixed size array, attaching a field name to any errors
Sourcefn decode_box_arr<const N: usize>(values: &[R]) -> Result<Box<[T; N]>>
fn decode_box_arr<const N: usize>(values: &[R]) -> Result<Box<[T; N]>>
Decode a boxed fixed size array.
Sourcefn decode_box_arr_wrap<const N: usize>(
values: &[R],
msg: &'static str,
) -> Result<Box<[T; N]>>
fn decode_box_arr_wrap<const N: usize>( values: &[R], msg: &'static str, ) -> Result<Box<[T; N]>>
Decode a boxed fixed size array, attaching a field name to any errors
Sourcefn decode_some(value: &Option<R>) -> Result<T>
fn decode_some(value: &Option<R>) -> Result<T>
Decode an optional field as a required one; fails if it’s None
.
Sourcefn decode_some_wrap(value: &Option<R>, msg: &'static str) -> Result<T>
fn decode_some_wrap(value: &Option<R>, msg: &'static str) -> Result<T>
Decode an optional field as a required one, attaching a field name to any errors. Returns error if the field is missing.
Sourcefn decode_opt_wrap(value: &Option<R>, msg: &'static str) -> Result<Option<T>>
fn decode_opt_wrap(value: &Option<R>, msg: &'static str) -> Result<Option<T>>
Decode an optional field, attaching a field name to any errors.
Return None
if the field is missing.
Sourcefn decode_enum(value: i32) -> Result<T>
fn decode_enum(value: i32) -> Result<T>
Decode the numeric representation of an enum into the domain type. Return an error if the value cannot be recognized.
Sourcefn decode_enum_wrap(value: i32, msg: &'static str) -> Result<T>
fn decode_enum_wrap(value: i32, msg: &'static str) -> Result<T>
Decode the numeric representation of an enum, attaching the field name to any errors.
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.