diff --git a/Cargo.toml b/Cargo.toml index 500766b..2557ba4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ description = "Small byte-sized generic key-value map type" keywords = ["map", "table", "small", "key", "value"] repository = "https://git.flanchan.moe/flanchan/smallmap" homepage= "https://git.flanchan.moe/flanchan/smallmap" -version = "1.0.0" +version = "1.0.1" authors = ["Avril "] edition = "2018" license = "MIT" diff --git a/src/lib.rs b/src/lib.rs index 0fe0509..5624298 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,25 +60,9 @@ pub trait Collapse: Eq /// A single page in a `Map`. Contains up to 256 key-value entries. #[repr(transparent)] -#[cfg_attr(nightly, derive(Debug,Clone,PartialEq,Eq,Ord,PartialOrd,Hash))] pub struct Page([Option<(TKey, TValue)>; MAX]); -#[cfg(not(nightly))] impl Clone for Page -{ - fn clone(&self) -> Self - { - #[inline(always)] fn copy_slice(dst: &mut [T], src: &[T]) - { - for (d, s) in dst.iter_mut().zip(src.iter()) - { - *d = s.clone() - } - } - let mut new = init::blank_page(); - copy_slice(&mut new[..], &self.0[..]); - Self(new) - } -} +mod page_impls; impl Page where K: Collapse @@ -158,17 +142,9 @@ where K: Collapse } /// A small hashtable-like map with byte sized key indecies. -#[cfg_attr(nightly, derive(Debug, Clone, PartialEq, Eq, Hash, Default))] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] pub struct Map(Vec>); -#[cfg(not(nightly))] impl Clone for Map -{ - fn clone(&self) -> Self - { - Self(self.0.clone()) - } -} - impl Map where K: Collapse { diff --git a/src/page_impls.rs b/src/page_impls.rs new file mode 100644 index 0000000..eb1cf43 --- /dev/null +++ b/src/page_impls.rs @@ -0,0 +1,47 @@ +//! Because we can't #derive big arrays on stable smh +use super::*; +use std::{ + fmt::{self, Debug,}, + hash, +}; + +impl Clone for Page +{ + fn clone(&self) -> Self + { + #[inline(always)] fn copy_slice(dst: &mut [T], src: &[T]) + { + for (d, s) in dst.iter_mut().zip(src.iter()) + { + *d = s.clone() + } + } + let mut new = init::blank_page(); + copy_slice(&mut new[..], &self.0[..]); + Self(new) + } +} + +impl Debug for Page +{ + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result + { + write!(f, "{:?}", &self.0[..]) + } +} + + +impl Eq for Page{} +impl PartialEq for Page +{ + #[inline] fn eq(&self, other: &Self) -> bool + { + &self.0[..] == &other.0[..] + } +} + +impl hash::Hash for Page { + #[inline] fn hash(&self, state: &mut H) { + (&self.0[..]).hash(state) + } +}