aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db/src/label.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-08-18 15:51:10 +0100
committerGitHub <[email protected]>2020-08-18 15:51:10 +0100
commit0df9ecedb4ecd667007457c88eaf4748cd627449 (patch)
tree55b43c677a213af8184483a857ea2e4631270547 /crates/ide_db/src/label.rs
parente81c310b6224946318b8e6af56a55021716ea9b5 (diff)
parentaa1a7a5414e59c7f1c6e74002df1b6a04937459e (diff)
Merge #5798
5798: Introduce Label r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ide_db/src/label.rs')
-rw-r--r--crates/ide_db/src/label.rs49
1 files changed, 49 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`
2use 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)]
11pub struct Label(String);
12
13impl PartialEq<str> for Label {
14 fn eq(&self, other: &str) -> bool {
15 self.0 == other
16 }
17}
18
19impl PartialEq<&'_ str> for Label {
20 fn eq(&self, other: &&str) -> bool {
21 self == *other
22 }
23}
24
25impl From<Label> for String {
26 fn from(label: Label) -> String {
27 label.0
28 }
29}
30
31impl 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
39impl fmt::Display for Label {
40 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 fmt::Display::fmt(&self.0, f)
42 }
43}
44
45impl fmt::Debug for Label {
46 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47 fmt::Debug::fmt(&self.0, f)
48 }
49}