Skip to content

Commit

Permalink
Created namespacing data models
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacShelton committed Sep 19, 2024
1 parent cc8e1b9 commit bb2e685
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/name.rs
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>),
}

0 comments on commit bb2e685

Please sign in to comment.