use crate::internal::Sealed;
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Eq, Clone, Hash, Deserialize)]
#[serde(transparent)]
pub struct Id(pub String);
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Serialize)]
#[serde(transparent)]
pub struct Ref<'a>(pub &'a str);
impl Id {
#[must_use]
pub fn as_ref(&self) -> Ref<'_> {
Ref(&self.0)
}
}
impl<'a> Ref<'a> {
#[must_use]
pub fn to_owned(&self) -> Id {
Id(self.0.into())
}
}
impl From<String> for Id {
#[must_use]
fn from(id: String) -> Self {
Self(id)
}
}
impl<'a> From<&'a str> for Ref<'a> {
#[must_use]
fn from(id: &'a str) -> Self {
Self(id)
}
}
impl<'a> PartialEq<Ref<'a>> for Id {
#[must_use]
fn eq(&self, other: &Ref<'a>) -> bool {
self.0 == other.0
}
}
impl<'a> PartialEq<Id> for Ref<'a> {
#[must_use]
fn eq(&self, other: &Id) -> bool {
self.0 == other.0
}
}
impl Sealed for Id {}
impl Sealed for Ref<'_> {}
#[allow(clippy::module_name_repetitions)] pub trait AsFileId: Sealed {
#[doc(hidden)]
fn as_file_id(&self) -> Ref<'_>;
}
impl AsFileId for Id {
#[must_use]
fn as_file_id(&self) -> Ref<'_> {
self.as_ref()
}
}
impl AsFileId for Ref<'_> {
#[must_use]
fn as_file_id(&self) -> Ref<'_> {
*self
}
}