use std::borrow::Cow;
use crate::datatype::DataType;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Generic(Cow<'static, str>);
impl Generic {
pub const fn new(name: Cow<'static, str>) -> Self {
Self(name)
}
pub fn name(&self) -> &Cow<'static, str> {
&self.0
}
pub fn reference(&self) -> Self {
self.clone()
}
}
impl From<Generic> for DataType {
fn from(v: Generic) -> Self {
DataType::Generic(v)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub struct GenericDefinition {
pub name: Cow<'static, str>,
pub default: Option<DataType>,
}
impl GenericDefinition {
pub const fn new(name: Cow<'static, str>, default: Option<DataType>) -> Self {
Self { name, default }
}
pub fn reference(&self) -> Generic {
Generic::new(self.name.clone())
}
}