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§
sourcefn message_name(&self) -> &'static str
fn message_name(&self) -> &'static str
message name as in proto file
sourcefn package_name(&self) -> &'static str
fn package_name(&self) -> &'static str
package name as in proto file
sourcefn type_url(&self) -> &'static str
fn type_url(&self) -> &'static str
the message proto type url e.g. type.googleapis.com/my.package.MyMessage
sourcefn new_instance(
&self,
data: Vec<u8>,
) -> Result<Box<dyn MessageSerde>, DecodeError>
fn new_instance( &self, data: Vec<u8>, ) -> Result<Box<dyn MessageSerde>, DecodeError>
Creates a new instance of this message using the protobuf encoded data
sourcefn try_encoded(&self) -> Result<Vec<u8>, EncodeError>
fn try_encoded(&self) -> Result<Vec<u8>, EncodeError>
Returns the encoded protobuf message as bytes
Implementations§
source§impl dyn MessageSerde
impl dyn MessageSerde
The implementation here is a direct copy of the impl dyn
of std::any::Any
!
sourcepub fn is<T>(&self) -> boolwhere
T: MessageSerde,
pub fn is<T>(&self) -> boolwhere
T: MessageSerde,
Returns true
if the inner type is the same as T
.
sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: MessageSerde,
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.
sourcepub fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: MessageSerde,
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.
sourcepub unsafe fn downcast_ref_unchecked<T>(&self) -> &Twhere
T: MessageSerde,
pub unsafe fn downcast_ref_unchecked<T>(&self) -> &Twhere
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.
sourcepub unsafe fn downcast_mut_unchecked<T>(&mut self) -> &mut Twhere
T: MessageSerde,
pub unsafe fn downcast_mut_unchecked<T>(&mut self) -> &mut Twhere
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.