1use std::fmt;
3
4use stdx::always;
5
6#[derive(Clone)]
13pub struct Label(String);
14
15impl PartialEq<str> for Label {
16 fn eq(&self, other: &str) -> bool {
17 self.0 == other
18 }
19}
20
21impl PartialEq<&'_ str> for Label {
22 fn eq(&self, other: &&str) -> bool {
23 self == *other
24 }
25}
26
27impl From<Label> for String {
28 fn from(label: Label) -> String {
29 label.0
30 }
31}
32
33impl Label {
34 pub fn new(label: String) -> Label {
35 always!(label.starts_with(char::is_uppercase) && !label.ends_with('.'));
36 Label(label)
37 }
38}
39
40impl fmt::Display for Label {
41 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42 fmt::Display::fmt(&self.0, f)
43 }
44}
45
46impl fmt::Debug for Label {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 fmt::Debug::fmt(&self.0, f)
49 }
50}