Skip to content

Commit

Permalink
refactor: remove SystemLibraryId and use DependencyName(String)
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat committed Jan 17, 2025
1 parent 43e0a83 commit ab26b55
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 44 deletions.
45 changes: 2 additions & 43 deletions package/src/dep/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,10 @@ use crate::Digest;

pub(crate) mod resolver;

/// A system library identifier
#[derive(
Debug, Copy, Clone, PartialEq, Eq, serde_repr::Serialize_repr, serde_repr::Deserialize_repr,
)]
#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
#[repr(u8)]
pub enum SystemLibraryId {
/// The standard library
Stdlib,
/// The base library
Miden,
}

impl core::str::FromStr for SystemLibraryId {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
// Compiler uses "std" and "base" to identify the standard and base libraries
// respectively. We also accept "stdlib" and "miden" as aliases for these libraries.
"std" | "stdlib" => Ok(Self::Stdlib),
"base" | "miden" => Ok(Self::Miden),
_ => Err(()),
}
}
}

/// The name of a dependency
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, derive_more::From)]
#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
pub enum DependencyName {
/// The dependency is a system library
System(SystemLibraryId),
/// The dependency is a user library with the given name
User(String),
}

impl From<String> for DependencyName {
fn from(s: String) -> Self {
if let Ok(id) = s.parse() {
DependencyName::System(id)
} else {
DependencyName::User(s)
}
}
}
pub struct DependencyName(String);

/// A package dependency
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion package/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub use self::{
DependencyResolver, LocalResolvedDependency, MemDependencyResolverByDigest,
ResolvedDependency,
},
Dependency, DependencyName, SystemLibraryId,
Dependency, DependencyName,
},
package::{MastArtifact, Package, PackageExport, PackageManifest},
};
Expand Down

0 comments on commit ab26b55

Please sign in to comment.