Trait prost_wkt_types::MessageSerde

source ·
pub trait MessageSerde: Message + Any + Serialize + Deserialize {
    // Required methods
    fn message_name(&self) -> &'static str;
    fn package_name(&self) -> &'static str;
    fn type_url(&self) -> &'static str;
    fn new_instance(
        &self,
        data: Vec<u8>,
    ) -> Result<Box<dyn MessageSerde>, DecodeError>;
    fn try_encoded(&self) -> Result<Vec<u8>, EncodeError>;
}
Expand description

Trait to support serialization and deserialization of prost messages.

Required Methods§

source

fn message_name(&self) -> &'static str

message name as in proto file

source

fn package_name(&self) -> &'static str

package name as in proto file

source

fn type_url(&self) -> &'static str

the message proto type url e.g. type.googleapis.com/my.package.MyMessage

source

fn new_instance( &self, data: Vec<u8>, ) -> Result<Box<dyn MessageSerde>, DecodeError>

Creates a new instance of this message using the protobuf encoded data

source

fn try_encoded(&self) -> Result<Vec<u8>, EncodeError>

Returns the encoded protobuf message as bytes

Implementations§

source§

impl dyn MessageSerde

The implementation here is a direct copy of the impl dyn of std::any::Any!

source

pub fn is<T>(&self) -> bool
where T: MessageSerde,

Returns true if the inner type is the same as T.

source

pub fn downcast_ref<T>(&self) -> Option<&T>
where T: MessageSerde,

Returns some reference to the inner value if it is of type T, or None if it isn’t.

source

pub fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: MessageSerde,

Returns some mutable reference to the boxed value if it is of type T, or None if it isn’t.

source

pub unsafe fn downcast_ref_unchecked<T>(&self) -> &T
where T: MessageSerde,

Returns a reference to the inner value as type dyn T.

§Safety

The contained value must be of type T. Calling this method with the incorrect type is undefined behavior.

source

pub unsafe fn downcast_mut_unchecked<T>(&mut self) -> &mut T
where T: MessageSerde,

Returns a mutable reference to the inner value as type dyn T.

§Safety

The contained value must be of type T. Calling this method with the incorrect type is undefined behavior.

Trait Implementations§

source§

impl<'typetag> Serialize for dyn MessageSerde + 'typetag

source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<'typetag> Serialize for dyn MessageSerde + Send + 'typetag

source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<'typetag> Serialize for dyn MessageSerde + Send + Sync + 'typetag

source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<'typetag> Serialize for dyn MessageSerde + Sync + 'typetag

source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Implementors§