-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc8e1b9
commit bb2e685
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::fmt::Display; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Hash)] | ||
pub struct Name { | ||
pub namespace: String, | ||
pub basename: String, | ||
} | ||
|
||
impl Name { | ||
pub fn plain(basename: impl Into<String>) -> Self { | ||
Self { | ||
namespace: "".into(), | ||
basename: basename.into(), | ||
} | ||
} | ||
|
||
pub fn into_plain(self) -> Option<String> { | ||
if self.namespace.is_empty() { | ||
Some(self.basename) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
pub fn as_plain_str(&self) -> Option<&str> { | ||
if self.namespace.is_empty() { | ||
Some(&self.basename) | ||
} else { | ||
None | ||
} | ||
} | ||
} | ||
|
||
impl Display for Name { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}{}", self.namespace, self.basename) | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Hash)] | ||
pub enum ResolvedName { | ||
Remote(Box<str>), | ||
Project(Box<str>), | ||
} |