added smallmap feature

master
Avril 4 years ago
parent 6e19585e48
commit 2a320b05a8
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -3,19 +3,17 @@ name = "refset"
description = "A non-owning HashSet"
repository = "https://git.flanchan.moe/flanchan/refset"
keywords = ["hash", "set", "reference"]
version = "0.1.1"
version = "0.2.0"
authors = ["Avril <flanchan@cumallover.me>"]
edition = "2018"
license= "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
[dependencies]
sha2 = "0.9"
serde = {version = "1.0", optional = true, features=["derive"]}
smallmap = {version = "1.1", optional = true} # serde here is kinda broken for now
smallmap = {version = "1.1.6", optional = true, features= ["serde"]}
[dev-dependencies]
serde_json = "1.0"

@ -11,6 +11,25 @@ use smallmap::{Collapse, Map};
#[cfg_attr(feature="serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SmallRefMap<T: ?Sized>(Map<HashType, ()>, PhantomData<Map<*const T, ()>>);
#[cfg(test)]
#[cfg(feature="serde")]
mod serde_tests
{
use super::*;
#[test]
fn ser_de()
{
let mut rmap = SmallRefMap::new();
rmap.insert("hello");
let string = serde_json::to_string(&rmap).expect("Ser failed");
println!("String {:?}", string);
let rmap2 = serde_json::from_str(&string[..]).expect("De failed)");
assert_eq!(rmap, rmap2);
}
}
unsafe impl<T: ?Sized + Send> Send for SmallRefMap<T>{}
unsafe impl<T: ?Sized + Send + Sync> Sync for SmallRefMap<T>{}

Loading…
Cancel
Save