use serde::{Deserialize, Serialize};
use std::{
fmt::{self, Debug}, ops::Index, slice::{self, SliceIndex}, vec
};
#[derive(Clone, Hash, Eq, PartialOrd, Serialize, Deserialize)]
pub struct List<T>(pub(crate) Vec<T>);
impl<T> List<T> {
pub fn iter(&self) -> slice::Iter<'_, T> {
self.0.iter()
}
}
impl<T> IntoIterator for List<T> {
type Item = T;
type IntoIter = vec::IntoIter<T>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
impl<T> From<Vec<T>> for List<T> {
fn from(vec: Vec<T>) -> Self {
Self(vec)
}
}
impl<T> Into<Vec<T>> for List<T> {
fn into(self) -> Vec<T> {
self.0
}
}
impl<T, U> PartialEq<List<U>> for List<T>
where
T: PartialEq<U>,
{
fn eq(&self, other: &List<U>) -> bool {
self.0 == other.0
}
}
impl<T, I> Index<I> for List<T>
where
I: SliceIndex<[T]>,
{
type Output = <I as SliceIndex<[T]>>::Output;
fn index(&self, index: I) -> &Self::Output {
self.0.index(index)
}
}
impl<T> Debug for List<T>
where
T: Debug,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_list().entries(self.iter()).finish()
}
}