]> git.lizzy.rs Git - rust.git/blob - src/tools/rust-analyzer/crates/ide-db/src/label.rs
Rollup merge of #102913 - SparrowLii:import-candidate, r=compiler-errors
[rust.git] / src / tools / rust-analyzer / crates / ide-db / src / label.rs
1 //! See [`Label`]
2 use std::fmt;
3
4 /// A type to specify UI label, like an entry in the list of assists. Enforces
5 /// proper casing:
6 ///
7 ///    Frobnicate bar
8 ///
9 /// Note the upper-case first letter and the absence of `.` at the end.
10 #[derive(Clone)]
11 pub struct Label(String);
12
13 impl PartialEq<str> for Label {
14     fn eq(&self, other: &str) -> bool {
15         self.0 == other
16     }
17 }
18
19 impl PartialEq<&'_ str> for Label {
20     fn eq(&self, other: &&str) -> bool {
21         self == *other
22     }
23 }
24
25 impl From<Label> for String {
26     fn from(label: Label) -> String {
27         label.0
28     }
29 }
30
31 impl Label {
32     pub fn new(label: String) -> Label {
33         assert!(label.starts_with(char::is_uppercase) && !label.ends_with('.'));
34         Label(label)
35     }
36 }
37
38 impl fmt::Display for Label {
39     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40         fmt::Display::fmt(&self.0, f)
41     }
42 }
43
44 impl fmt::Debug for Label {
45     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46         fmt::Debug::fmt(&self.0, f)
47     }
48 }