use std::{
borrow::Borrow,
fmt::{self, Display},
ops::{Deref, DerefMut},
};
use serde::{Deserialize, Serialize};
use crate::{Id, IdInvalidFmt};
#[cfg_attr(
all(feature = "schemars", not(feature = "test")),
derive(schemars::JsonSchema)
)]
#[derive(Clone, Debug, Hash, PartialEq, Eq, Deserialize, Serialize)]
pub struct EdgeGroupId<'s>(Id<'s>);
impl<'s> EdgeGroupId<'s> {
pub fn new(id: &'s str) -> Result<Self, IdInvalidFmt<'s>> {
Id::new(id).map(EdgeGroupId)
}
pub fn into_inner(self) -> Id<'s> {
self.0
}
pub fn into_static(self) -> EdgeGroupId<'static> {
EdgeGroupId(self.0.into_static())
}
}
impl<'s> From<Id<'s>> for EdgeGroupId<'s> {
fn from(id: Id<'s>) -> Self {
EdgeGroupId(id)
}
}
impl<'s> AsRef<Id<'s>> for EdgeGroupId<'s> {
fn as_ref(&self) -> &Id<'s> {
&self.0
}
}
impl<'s> Borrow<Id<'s>> for EdgeGroupId<'s> {
fn borrow(&self) -> &Id<'s> {
&self.0
}
}
impl<'s> Deref for EdgeGroupId<'s> {
type Target = Id<'s>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<'s> DerefMut for EdgeGroupId<'s> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl<'s> Display for EdgeGroupId<'s> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}