use std::{
fmt::{Debug, Display, Formatter},
hash::Hash,
sync::Arc,
};
use semver::Version;
mod convert;
mod display;
#[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
pub struct WasiPublisher {
organization: Arc<str>,
project: Arc<str>,
}
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
pub struct WasiModule {
pub package: Option<WasiPublisher>,
pub name: Arc<str>,
pub version: Option<Version>,
}
impl WasiModule {
pub fn new<S>(name: S) -> Self
where
S: Into<Arc<str>>,
{
let name = name.into();
if name.contains(&['/', ':']) {
panic!("Invalid module name: {}", name);
}
Self { package: None, name: name.into(), version: None }
}
pub fn with_publisher(self, publisher: WasiPublisher) -> Self {
Self { package: Some(publisher), ..self }
}
pub fn with_version(self, version: Version) -> Self {
Self { version: Some(version), ..self }
}
pub fn with_project<O, P>(self, organization: O, project: P) -> Self
where
O: Into<Arc<str>>,
P: Into<Arc<str>>,
{
Self { package: Some(WasiPublisher { organization: organization.into(), project: project.into() }), ..self }
}
}