Introduce PackageName::to_str and From instance

This commit is contained in:
Richard Feldman 2022-06-16 14:27:11 -04:00
parent a5ba3581df
commit 203a9aba02
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798
3 changed files with 26 additions and 5 deletions

View file

@ -53,7 +53,29 @@ pub enum VersionComparison {
}
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct PackageName<'a>(pub &'a str);
pub struct PackageName<'a>(&'a str);
impl<'a> PackageName<'a> {
pub fn to_str(self) -> &'a str {
self.0
}
pub fn as_str(&self) -> &'a str {
self.0
}
}
impl<'a> From<PackageName<'a>> for &'a str {
fn from(name: PackageName<'a>) -> &'a str {
name.0
}
}
impl<'a> From<&'a str> for PackageName<'a> {
fn from(string: &'a str) -> Self {
Self(string)
}
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub struct ModuleName<'a>(&'a str);