protobuf/message_full.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
use std::fmt;
use crate::message_dyn::MessageDyn;
use crate::reflect::reflect_eq::ReflectEqMode;
use crate::reflect::MessageDescriptor;
use crate::reflect::ProtobufValue;
use crate::Message;
/// Trait implemented for all the generated messages, except when lite runtime is enabled.
///
/// When lite runtime is enabled, only `MessageLite` is implemented.
///
/// * Generated messages are generated from `.proto` files
/// * Dynamic messages can be created without code generation using only parsed proto files
/// (see [FileDescriptor::new_dynamic](crate::reflect::FileDescriptor::new_dynamic)).
///
/// Also, generated messages implement `Default + PartialEq`
///
/// This trait is sized, there's accompanying [`MessageDyn`](crate::MessageDyn) trait
/// which is implemented for all messages which can be used in functions
/// without making message a function type parameter.
///
/// ## `Display`
///
/// [`Display`](fmt::Display) implementation for messages does protobuf text format.
/// See [`text_format`](crate::text_format) for more details.
pub trait MessageFull: Message + ProtobufValue + fmt::Debug + fmt::Display {
/// Get message descriptor for message type.
///
/// ```
/// # use protobuf::MessageFull;
/// # fn foo<MyMessage: MessageFull>() {
/// let descriptor = MyMessage::descriptor();
/// assert_eq!("MyMessage", descriptor.name());
/// # }
/// ```
fn descriptor() -> MessageDescriptor;
/// Reflective equality.
///
/// # See also
///
/// [`dyn Message::reflect_eq_dyn()`], `dyn` version of this function.
fn reflect_eq(&self, other: &Self, mode: &ReflectEqMode) -> bool {
<dyn MessageDyn>::reflect_eq_dyn(self, other, mode)
}
}