fix derive issue

master
Avril 4 years ago
parent 2afba2952b
commit c853138e00
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -4,7 +4,7 @@ description = "Small byte-sized generic key-value map type"
keywords = ["map", "table", "small", "key", "value"] keywords = ["map", "table", "small", "key", "value"]
repository = "https://git.flanchan.moe/flanchan/smallmap" repository = "https://git.flanchan.moe/flanchan/smallmap"
homepage= "https://git.flanchan.moe/flanchan/smallmap" homepage= "https://git.flanchan.moe/flanchan/smallmap"
version = "1.0.0" version = "1.0.1"
authors = ["Avril <flanchan@cumallover.me>"] authors = ["Avril <flanchan@cumallover.me>"]
edition = "2018" edition = "2018"
license = "MIT" license = "MIT"

@ -60,25 +60,9 @@ pub trait Collapse: Eq
/// A single page in a `Map`. Contains up to 256 key-value entries. /// A single page in a `Map`. Contains up to 256 key-value entries.
#[repr(transparent)] #[repr(transparent)]
#[cfg_attr(nightly, derive(Debug,Clone,PartialEq,Eq,Ord,PartialOrd,Hash))]
pub struct Page<TKey,TValue>([Option<(TKey, TValue)>; MAX]); pub struct Page<TKey,TValue>([Option<(TKey, TValue)>; MAX]);
#[cfg(not(nightly))] impl<K: Clone, V: Clone> Clone for Page<K,V> mod page_impls;
{
fn clone(&self) -> Self
{
#[inline(always)] fn copy_slice<T: Clone>(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<K,V> Page<K,V> impl<K,V> Page<K,V>
where K: Collapse where K: Collapse
@ -158,17 +142,9 @@ where K: Collapse
} }
/// A small hashtable-like map with byte sized key indecies. /// 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<TKey, TValue>(Vec<Page<TKey,TValue>>); pub struct Map<TKey, TValue>(Vec<Page<TKey,TValue>>);
#[cfg(not(nightly))] impl<K: Clone, V: Clone> Clone for Map<K,V>
{
fn clone(&self) -> Self
{
Self(self.0.clone())
}
}
impl<K,V> Map<K,V> impl<K,V> Map<K,V>
where K: Collapse where K: Collapse
{ {

@ -0,0 +1,47 @@
//! Because we can't #derive big arrays on stable smh
use super::*;
use std::{
fmt::{self, Debug,},
hash,
};
impl<K: Clone, V: Clone> Clone for Page<K,V>
{
fn clone(&self) -> Self
{
#[inline(always)] fn copy_slice<T: Clone>(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<K: Debug, V:Debug> Debug for Page<K,V>
{
#[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
write!(f, "{:?}", &self.0[..])
}
}
impl<K: Eq, V: Eq> Eq for Page<K,V>{}
impl<K: PartialEq, V: PartialEq> PartialEq for Page<K,V>
{
#[inline] fn eq(&self, other: &Self) -> bool
{
&self.0[..] == &other.0[..]
}
}
impl<K: hash::Hash, V: hash::Hash> hash::Hash for Page<K,V> {
#[inline] fn hash<H: hash::Hasher>(&self, state: &mut H) {
(&self.0[..]).hash(state)
}
}
Loading…
Cancel
Save