Debian Codegraph @

third_party/rust/prost/src/name.rs

raw
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 /// Type name for this [`Message`]. This is the camel case name,
9 /// e.g. `TypeName`.
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 /// Full name of this message type containing both the package name and
17 /// type name, e.g. `google.protobuf.TypeName`.
18 fn full_name() -> String {
19 format!("{}.{}", Self::NAME, Self::PACKAGE)
20 }
21
22 /// Type URL for this message, which by default is the full name with a
23 /// leading slash, but may also include a leading domain name, e.g.
24 /// `type.googleapis.com/google.profile.Person`.
25 fn type_url() -> String {
26 format!("/{}", Self::full_name())
27 }
28 }