Skip to content

Commit 00820af

Browse files
authored
Merge pull request #33 from little-dude/master
Drop the `postcard` dependency
2 parents 154d0db + 4f36a8f commit 00820af

File tree

5 files changed

+8
-26
lines changed

5 files changed

+8
-26
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ serde = { version = "1", optional = true }
2020

2121
[dev-dependencies]
2222
clap = { version = "4", features = ["derive"] }
23-
postcard = { version = "1", features = ["use-std"] }
2423
rand = "0.8"
2524
serde_json = { version = "1" }
2625

src/map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! A map based on a patricia tree.
22
use crate::node;
3-
#[cfg(feature = "serde")]
3+
#[cfg(any(test, feature = "serde"))]
44
use crate::node::Node;
55
use crate::tree::{self, PatriciaTree};
66
use crate::{BorrowedBytes, Bytes};
@@ -105,7 +105,7 @@ impl<K, V> GenericPatriciaMap<K, V> {
105105
}
106106
}
107107

108-
#[cfg(feature = "serde")]
108+
#[cfg(any(test, feature = "serde"))]
109109
pub(crate) fn as_node(&self) -> &Node<V> {
110110
self.tree.root()
111111
}

src/serialization.rs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -261,25 +261,8 @@ mod tests {
261261
input.sort();
262262

263263
let map: PatriciaMap<u32> = input.iter().cloned().collect();
264-
let bytes = postcard::to_allocvec(&map).unwrap();
265-
let map: PatriciaMap<u32> = postcard::from_bytes(&bytes).unwrap();
266-
267-
assert_eq!(map.len(), 3);
268-
assert_eq!(map.into_iter().collect::<Vec<_>>(), input);
269-
}
270-
271-
#[test]
272-
fn serde_json_works() {
273-
let mut input = vec![
274-
(Vec::from("foo"), 1u32),
275-
("bar".into(), 2),
276-
("baz".into(), 3),
277-
];
278-
input.sort();
279-
280-
let map: PatriciaMap<u32> = input.iter().cloned().collect();
281-
let json = serde_json::to_string(&map).unwrap();
282-
let map: PatriciaMap<u32> = serde_json::from_str(&json).unwrap();
264+
let serialized = serde_json::to_vec(&map).unwrap();
265+
let map: PatriciaMap<u32> = serde_json::from_slice(serialized.as_slice()).unwrap();
283266

284267
assert_eq!(map.len(), 3);
285268
assert_eq!(map.into_iter().collect::<Vec<_>>(), input);
@@ -293,8 +276,8 @@ mod tests {
293276
input.sort();
294277

295278
let map: PatriciaMap<u32> = input.iter().cloned().collect();
296-
let bytes = postcard::to_allocvec(&map).unwrap();
297-
let map: PatriciaMap<u32> = postcard::from_bytes(&bytes).unwrap();
279+
let serialized = serde_json::to_vec(&map).unwrap();
280+
let map: PatriciaMap<u32> = serde_json::from_slice(serialized.as_slice()).unwrap();
298281

299282
assert_eq!(map.len(), 10000);
300283
assert_eq!(map.into_iter().collect::<Vec<_>>(), input);

src/set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<T> GenericPatriciaSet<T> {
9292
}
9393
}
9494

95-
#[cfg(feature = "serde")]
95+
#[cfg(any(test, feature = "serde"))]
9696
pub(crate) fn as_node(&self) -> &Node<()> {
9797
self.map.as_node()
9898
}

src/tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl<V> PatriciaTree<V> {
1616
len: 0,
1717
}
1818
}
19-
#[cfg(feature = "serde")]
19+
#[cfg(any(test, feature = "serde"))]
2020
pub fn root(&self) -> &Node<V> {
2121
&self.root
2222
}

0 commit comments

Comments
 (0)