use super::hosting_category;
use hosting_category::HostingCategory;
use std::fmt;
use std::sync::LazyLock;
#[derive(Debug, Clone, Copy)]
pub enum NetworkTopology {
NotNetworked,
Centralized,
Decentralized,
Distributed,
}
pub struct HostingTypeInfo {
pub name: &'static str,
pub url: &'static str,
pub network_topology: NetworkTopology,
}
pub static HTI_APPROPEDIA: LazyLock<HostingTypeInfo> = LazyLock::new(|| HostingTypeInfo {
name: "Appropedia OSH Wiki",
url: "https://appropedia.org/",
network_topology: NetworkTopology::Centralized,
});
pub static HTI_MANIFESTS_REPO: LazyLock<HostingTypeInfo> = LazyLock::new(|| HostingTypeInfo {
name: "Git repositories containing manifests",
url: "https://git-scm.com",
network_topology: NetworkTopology::Decentralized,
});
pub static HTI_OSHWA: LazyLock<HostingTypeInfo> = LazyLock::new(|| HostingTypeInfo {
name: "OSHWA OSH Certification Platform",
url: "https://certification.oshwa.org/",
network_topology: NetworkTopology::Centralized,
});
pub static HTI_THINGIVERSE: LazyLock<HostingTypeInfo> = LazyLock::new(|| HostingTypeInfo {
name: "Thingiverse - Platform for sharing 3D printable things",
url: "https://www.thingiverse.com/",
network_topology: NetworkTopology::Centralized,
});
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum HostingType {
Appropedia,
ForgeJo,
GitHub,
GitLab,
Oshwa,
Thingiverse,
ManifestsRepo,
}
impl AsRef<str> for HostingType {
fn as_ref(&self) -> &str {
match self {
Self::Appropedia => "SW|appropedia.org",
Self::ForgeJo => "SW|forgejo.org",
Self::GitHub => "SW|github.com",
Self::GitLab => "SW|gitlab.com",
Self::Oshwa => "SW|oshwa.org",
Self::Thingiverse => "SW|thingiverse.com",
Self::ManifestsRepo => "SW|git-scm.com", }
}
}
impl fmt::Display for HostingType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(self.as_ref())
}
}
impl HostingType {
#[must_use]
pub const fn category(&self) -> HostingCategory {
match self {
Self::ForgeJo | Self::GitHub | Self::GitLab => HostingCategory::Forge,
Self::Appropedia | Self::Oshwa | Self::Thingiverse | Self::ManifestsRepo => {
HostingCategory::Other
}
}
}
#[must_use]
pub fn info(&self) -> &'static HostingTypeInfo {
match self {
Self::ForgeJo => todo!("Implement"),
Self::GitHub => todo!("Implement"),
Self::GitLab => todo!("Implement"),
Self::Appropedia => &HTI_APPROPEDIA,
Self::Oshwa => &HTI_OSHWA,
Self::Thingiverse => &HTI_THINGIVERSE,
Self::ManifestsRepo => &HTI_MANIFESTS_REPO,
}
}
}