use std::{borrow::Cow, fmt};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ModuleId(Cow<'static, str>);
impl ModuleId {
#[must_use]
pub const fn new(id: &'static str) -> Self {
Self(Cow::Borrowed(id))
}
#[must_use]
#[allow(clippy::missing_const_for_fn)] pub fn from_string(id: String) -> Self {
Self(Cow::Owned(id))
}
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
#[must_use]
pub const fn is_static(&self) -> bool {
matches!(self.0, Cow::Borrowed(_))
}
#[must_use]
pub const fn is_dynamic(&self) -> bool {
matches!(self.0, Cow::Owned(_))
}
}
impl fmt::Display for ModuleId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl From<&'static str> for ModuleId {
fn from(s: &'static str) -> Self {
Self::new(s)
}
}
impl From<String> for ModuleId {
fn from(s: String) -> Self {
Self::from_string(s)
}
}