nyar_wasm/symbols/wasi_publisher/
mod.rs1use std::{
2 fmt::{Debug, Display, Formatter},
3 hash::Hash,
4 sync::Arc,
5};
6
7use semver::Version;
8
9mod convert;
10mod display;
11
12#[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
14pub struct WasiPublisher {
15 organization: Arc<str>,
16 project: Arc<str>,
17}
18
19#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
21pub struct WasiModule {
22 pub package: Option<WasiPublisher>,
23 pub name: Arc<str>,
24 pub version: Option<Version>,
25}
26
27impl WasiModule {
28 pub fn new<S>(name: S) -> Self
30 where
31 S: Into<Arc<str>>,
32 {
33 let name = name.into();
34 if name.contains(&['/', ':']) {
35 panic!("Invalid module name: {}", name);
36 }
37 Self { package: None, name: name.into(), version: None }
38 }
39 pub fn with_publisher(self, publisher: WasiPublisher) -> Self {
41 Self { package: Some(publisher), ..self }
42 }
43 pub fn with_version(self, version: Version) -> Self {
45 Self { version: Some(version), ..self }
46 }
47 pub fn with_project<O, P>(self, organization: O, project: P) -> Self
49 where
50 O: Into<Arc<str>>,
51 P: Into<Arc<str>>,
52 {
53 Self { package: Some(WasiPublisher { organization: organization.into(), project: project.into() }), ..self }
54 }
55}