diff options
Diffstat (limited to 'crates/ide_db')
-rw-r--r-- | crates/ide_db/src/label.rs | 49 | ||||
-rw-r--r-- | crates/ide_db/src/lib.rs | 1 |
2 files changed, 50 insertions, 0 deletions
diff --git a/crates/ide_db/src/label.rs b/crates/ide_db/src/label.rs new file mode 100644 index 000000000..c0e89e72f --- /dev/null +++ b/crates/ide_db/src/label.rs | |||
@@ -0,0 +1,49 @@ | |||
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: impl Into<String>) -> Label { | ||
33 | let label = label.into(); | ||
34 | assert!(label.starts_with(char::is_uppercase) && !label.ends_with('.')); | ||
35 | Label(label) | ||
36 | } | ||
37 | } | ||
38 | |||
39 | impl fmt::Display for Label { | ||
40 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
41 | fmt::Display::fmt(&self.0, f) | ||
42 | } | ||
43 | } | ||
44 | |||
45 | impl fmt::Debug for Label { | ||
46 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
47 | fmt::Debug::fmt(&self.0, f) | ||
48 | } | ||
49 | } | ||
diff --git a/crates/ide_db/src/lib.rs b/crates/ide_db/src/lib.rs index fd474cd0f..70ada02f3 100644 --- a/crates/ide_db/src/lib.rs +++ b/crates/ide_db/src/lib.rs | |||
@@ -2,6 +2,7 @@ | |||
2 | //! | 2 | //! |
3 | //! It is mainly a `HirDatabase` for semantic analysis, plus a `SymbolsDatabase`, for fuzzy search. | 3 | //! It is mainly a `HirDatabase` for semantic analysis, plus a `SymbolsDatabase`, for fuzzy search. |
4 | 4 | ||
5 | pub mod label; | ||
5 | pub mod line_index; | 6 | pub mod line_index; |
6 | pub mod symbol_index; | 7 | pub mod symbol_index; |
7 | pub mod change; | 8 | pub mod change; |