Debian Codegraph @

src/name.rs

raw symbols SCIP
1 use superrust-analyzer cargo mediatype 0.23.0 crate/::parserust-analyzer cargo mediatype 0.23.0 parse/::*;
2 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::{borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#, fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#};
3 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::{
4 cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#,
5 hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/::{Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#, Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#},
6 };
7
8 /// A media-type name.
9 ///
10 /// A valid name has the following requirements:
11 ///
12 /// - The first character must be an alphabet or a number.
13 /// - The subsequent characters must be alphabets, numbers or `!#$&-^_.+%*'`.
14 /// - Length of the name can not exceed 127 bytes.
15 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
16 pub struct Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'a>(&'a str);
17
18 impl<'a> Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'a> {
19 /// Constructs a `Name`.
20 ///
21 /// If the string is not valid as a name, returns `None`.
22 #[must_use]
23 pub fn newrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'a>`]new().(s: &'a str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'a>`]> {
24 if is_restricted_namerust-analyzer cargo mediatype 0.23.0 parse/is_restricted_name().(s) {
25 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'a>`](s))
26 } else {
27 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
28 }
29 }
30
31 /// Returns the underlying string.
32 #[must_use]
33 pub const fn as_strrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'a>`]as_str().(&self) -> &'a str {
34 self.0rust-analyzer cargo mediatype 0.23.0 name/Name#0.
35 }
36
37 /// The maximum byte length of a name.
38 pub const MAX_LENGTHrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'a>`]MAX_LENGTH.: usize = 127;
39
40 /// Constructs a `Name` without validation.
41 pub const fn new_uncheckedrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'a>`]new_unchecked().(s: &'a str) -> Selfrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'a>`] {
42 Selfrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'a>`](s)
43 }
44 }
45
46 impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {
47 fn fmtrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
48 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(self.0rust-analyzer cargo mediatype 0.23.0 name/Name#0.)
49 }
50 }
51
52 impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str> for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {
53 fn as_refrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`AsRef<str>`]as_ref().(&self) -> &str {
54 self.0rust-analyzer cargo mediatype 0.23.0 name/Name#0.
55 }
56 }
57
58 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {
59 fn eqrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq().(&self, other: &Selfrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]) -> bool {
60 self.0rust-analyzer cargo mediatype 0.23.0 name/Name#0..eq_ignore_ascii_caserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]eq_ignore_ascii_case().(other.as_refrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`AsRef<str>`]as_ref().())
61 }
62 }
63
64 impl Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {}
65
66 impl PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd# for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {
67 fn partial_cmprust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialOrd<Self>`]partial_cmp().(&self, other: &Selfrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialOrd<Self>`]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> {
68 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.cmprust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][Ord]cmp().(other))
69 }
70 }
71
72 impl Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord# for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {
73 fn cmprust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][Ord]cmp().(&self, other: &Selfrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][Ord]) -> Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering# {
74 self.0rust-analyzer cargo mediatype 0.23.0 name/Name#0.
75 .charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().()
76 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|c| c.to_ascii_lowercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]to_ascii_lowercase().())
77 .cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cmp().(other.0rust-analyzer cargo mediatype 0.23.0 name/Name#0..charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|c| c.to_ascii_lowercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]to_ascii_lowercase().()))
78 }
79 }
80
81 impl Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {
82 fn hashrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][Hash]hash().<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) {
83 self.0rust-analyzer cargo mediatype 0.23.0 name/Name#0..to_ascii_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_ascii_lowercase().().hashrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Hash]hash().(state);
84 }
85 }
86
87 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {
88 fn eqrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<String>`]eq().(&self, other: &Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> bool {
89 self.eqrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<str>`]eq().(other.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().())
90 }
91 }
92
93 impl PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {
94 fn partial_cmprust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialOrd<String>`]partial_cmp().(&self, other: &Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> {
95 self.partial_cmprust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialOrd<str>`]partial_cmp().(other.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().())
96 }
97 }
98
99 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<&Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {
100 fn eqrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<&String>`]eq().(&self, other: &&Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> bool {
101 self.eqrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<str>`]eq().(other.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().())
102 }
103 }
104
105 impl PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#<&Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {
106 fn partial_cmprust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialOrd<&String>`]partial_cmp().(&self, other: &&Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> {
107 self.partial_cmprust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialOrd<str>`]partial_cmp().(other.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().())
108 }
109 }
110
111 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<str> for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {
112 fn eqrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<str>`]eq().(&self, other: &str) -> bool {
113 self.0rust-analyzer cargo mediatype 0.23.0 name/Name#0..eq_ignore_ascii_caserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]eq_ignore_ascii_case().(other)
114 }
115 }
116
117 impl PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#<str> for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {
118 fn partial_cmprust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialOrd<str>`]partial_cmp().(&self, other: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> {
119 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(
120 self.0rust-analyzer cargo mediatype 0.23.0 name/Name#0.
121 .charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().()
122 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|c| c.to_ascii_lowercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]to_ascii_lowercase().())
123 .cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cmp().(other.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|c| c.to_ascii_lowercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]to_ascii_lowercase().())),
124 )
125 }
126 }
127
128 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<&str> for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {
129 fn eqrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<&str>`]eq().(&self, other: &&str) -> bool {
130 self.eqrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<str>`]eq().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().other)
131 }
132 }
133
134 impl PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#<&str> for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {
135 fn partial_cmprust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialOrd<&str>`]partial_cmp().(&self, other: &&str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> {
136 self.partial_cmprust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialOrd<str>`]partial_cmp().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().other)
137 }
138 }
139
140 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, str>> for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {
141 fn eqrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Cow<'_, str>>`]eq().(&self, other: &Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, str>) -> bool {
142 self.eqrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<str>`]eq().(other.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, T>`][`AsRef<T>`]as_ref().())
143 }
144 }
145
146 impl PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, str>> for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {
147 fn partial_cmprust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialOrd<Cow<'_, str>>`]partial_cmp().(&self, other: &Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, str>) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> {
148 self.partial_cmprust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialOrd<str>`]partial_cmp().(other.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, T>`][`AsRef<T>`]as_ref().())
149 }
150 }
151
152 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<&Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, str>> for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {
153 fn eqrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<&Cow<'_, str>>`]eq().(&self, other: &&Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, str>) -> bool {
154 self.eqrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<str>`]eq().(other.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[`&T`][`AsRef<U>`]as_ref().())
155 }
156 }
157
158 impl PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#<&Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, str>> for Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'_> {
159 fn partial_cmprust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialOrd<&Cow<'_, str>>`]partial_cmp().(&self, other: &&Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, str>) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> {
160 self.partial_cmprust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialOrd<str>`]partial_cmp().(other.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[`&T`][`AsRef<U>`]as_ref().())
161 }
162 }