use super::{DataFormat, DataFormatKind};
use std::fmt;
use std::hash::{Hash, Hasher};
use std::marker::PhantomData;
use std::ops::Deref;
pub struct DataFormatOf<T> {
format: DataFormat,
_data_type: PhantomData<fn() -> T>,
}
impl<T: 'static> DataFormatOf<T> {
pub(super) fn new(kind: DataFormatKind, identifier: &str) -> Self {
Self {
format: DataFormat::new(kind, identifier, Some(std::any::TypeId::of::<T>())),
_data_type: PhantomData,
}
}
}
impl<T> DataFormatOf<T> {
#[inline]
pub fn as_data_format(&self) -> &DataFormat {
&self.format
}
}
impl<T> Deref for DataFormatOf<T> {
type Target = DataFormat;
#[inline]
fn deref(&self) -> &DataFormat {
&self.format
}
}
impl<T> Clone for DataFormatOf<T> {
fn clone(&self) -> Self {
Self { format: self.format.clone(), _data_type: PhantomData }
}
}
impl<T> From<DataFormatOf<T>> for DataFormat {
fn from(value: DataFormatOf<T>) -> DataFormat {
value.format
}
}
impl<T, U> PartialEq<DataFormatOf<U>> for DataFormatOf<T> {
#[inline]
fn eq(&self, other: &DataFormatOf<U>) -> bool {
self.format == other.format
}
}
impl<T> Eq for DataFormatOf<T> {}
impl<T> PartialEq<DataFormat> for DataFormatOf<T> {
#[inline]
fn eq(&self, other: &DataFormat) -> bool {
self.format == *other
}
}
impl<T> PartialEq<DataFormatOf<T>> for DataFormat {
#[inline]
fn eq(&self, other: &DataFormatOf<T>) -> bool {
*self == other.format
}
}
impl<T> Hash for DataFormatOf<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.format.hash(state)
}
}
impl<T> fmt::Display for DataFormatOf<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.format, f)
}
}
impl<T> fmt::Debug for DataFormatOf<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.format, f)
}
}