xref: /aosp_15_r20/external/cronet/third_party/rust/chromium_crates_io/vendor/prost-0.12.3/src/name.rs (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 //! Support for associating type name information with a [`Message`].
2 
3 use crate::Message;
4 use alloc::{format, string::String};
5 
6 /// Associate a type name with a [`Message`] type.
7 pub trait Name: Message {
8     /// Simple name for this [`Message`].
9     /// This name is the same as it appears in the source .proto file, e.g. `FooBar`.
10     const NAME: &'static str;
11 
12     /// Package name this message type is contained in. They are domain-like
13     /// and delimited by `.`, e.g. `google.protobuf`.
14     const PACKAGE: &'static str;
15 
16     /// Fully-qualified unique name for this [`Message`].
17     /// It's prefixed with the package name and names of any parent messages,
18     /// e.g. `google.rpc.BadRequest.FieldViolation`.
19     /// By default, this is the package name followed by the message name.
20     /// Fully-qualified names must be unique within a domain of Type URLs.
full_name() -> String21     fn full_name() -> String {
22         format!("{}.{}", Self::PACKAGE, Self::NAME)
23     }
24 
25     /// Type URL for this [`Message`], which by default is the full name with a
26     /// leading slash, but may also include a leading domain name, e.g.
27     /// `type.googleapis.com/google.profile.Person`.
28     /// This can be used when serializing with the [`Any`] type.
type_url() -> String29     fn type_url() -> String {
30         format!("/{}", Self::full_name())
31     }
32 }
33