Skip to content

Commit bb2e685

Browse files
committed
Created namespacing data models
1 parent cc8e1b9 commit bb2e685

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

Diff for: src/name.rs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use std::fmt::Display;
2+
3+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
4+
pub struct Name {
5+
pub namespace: String,
6+
pub basename: String,
7+
}
8+
9+
impl Name {
10+
pub fn plain(basename: impl Into<String>) -> Self {
11+
Self {
12+
namespace: "".into(),
13+
basename: basename.into(),
14+
}
15+
}
16+
17+
pub fn into_plain(self) -> Option<String> {
18+
if self.namespace.is_empty() {
19+
Some(self.basename)
20+
} else {
21+
None
22+
}
23+
}
24+
25+
pub fn as_plain_str(&self) -> Option<&str> {
26+
if self.namespace.is_empty() {
27+
Some(&self.basename)
28+
} else {
29+
None
30+
}
31+
}
32+
}
33+
34+
impl Display for Name {
35+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36+
write!(f, "{}{}", self.namespace, self.basename)
37+
}
38+
}
39+
40+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
41+
pub enum ResolvedName {
42+
Remote(Box<str>),
43+
Project(Box<str>),
44+
}

0 commit comments

Comments
 (0)