diff --git a/src/name.rs b/src/name.rs new file mode 100644 index 00000000..f2bdb589 --- /dev/null +++ b/src/name.rs @@ -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) -> Self { + Self { + namespace: "".into(), + basename: basename.into(), + } + } + + pub fn into_plain(self) -> Option { + 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), + Project(Box), +}