use super::StringIndex;
use core::fmt;
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct StringId<I = u16>(I);
impl<I> StringId<I> {
#[inline]
pub const fn new(raw: I) -> Self {
Self(raw)
}
#[inline]
pub fn into_raw(self) -> I {
self.0
}
}
impl<I: StringIndex> StringId<I> {
#[inline]
pub fn into_usize(self) -> usize {
self.0.to_usize()
}
}
impl StringId<u32> {
#[inline]
pub const fn into_u32(self) -> u32 {
self.0
}
}
impl<I> From<I> for StringId<I> {
#[inline]
fn from(value: I) -> Self {
Self(value)
}
}
macro_rules! impl_raw_from_string_id {
($($ty:ty),+ $(,)?) => {
$(
impl From<StringId<$ty>> for $ty {
#[inline]
fn from(value: StringId<$ty>) -> Self {
value.0
}
}
)+
};
}
impl_raw_from_string_id!(u8, u16, u32, u64, usize);
impl<I: fmt::Display> fmt::Display for StringId<I> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}