Skip to content

Commit

Permalink
Add BTreeSet and HashSet
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtoth committed Nov 8, 2023
1 parent bc002a7 commit d141da8
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ create_visitor!(
deserialize_string!(Visitor, Type);

derive_extension_types!(super::Type);
serde_seq!(
std::collections::HashSet<super::Type>,
super::Type,
std::collections::HashSet::with_capacity,
insert,
hash_set
);
7 changes: 7 additions & 0 deletions src/header_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ create_visitor!(Visitor, Type, EXPECT_MESSAGE, (visit_str, &str));
deserialize_str!(Visitor, Type);

derive_extension_types!(super::Type);
serde_seq!(
std::collections::HashSet<super::Type>,
super::Type,
std::collections::HashSet::with_capacity,
insert,
hash_set
);
14 changes: 14 additions & 0 deletions src/header_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,17 @@ where
}

derive_extension_types!(super::Type);
serde_seq!(
std::collections::HashSet<super::Type>,
super::Type,
std::collections::HashSet::with_capacity,
insert,
hash_set
);
serde_seq!(
std::collections::BTreeSet<super::Type>,
super::Type,
|_| std::collections::BTreeSet::new(),
insert,
btree_set
);
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! ## [`serde`] extensions for the [`http`] crate types
//!
//! Allows serializing and deserializing the following types from [`http`]:
//! - [`Response`](response)
//! - [`Request`](request)
//! - [`Response`](response)
//! - [`HeaderMap`](header_map)
//! - [`StatusCode`](status_code)
//! - [`Uri`](uri)
Expand All @@ -23,6 +23,8 @@
//! - [`LinkedList`](std::collections::LinkedList)
//! - [`HashMap`](std::collections::HashMap) in the `Value` position
//! - [`BTreeMap`](std::collections::BTreeMap) in the `Value` position
//! - [`HashSet`](std::collections::HashSet) for all except `HeaderMap`, `Request`, and `Response`
//! - [`BTreeSet`](std::collections::BTreeSet) only for `HeaderValue`, `StatusCode`, and `Version`
//!
//! ## Usage
//!
Expand Down
4 changes: 2 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ macro_rules! serde_seq {
#[derive(serde::Serialize)]
struct TempSer<'a$(, $generic: serde::Serialize)?>(#[serde(with = "super")] &'a $ty);


#[allow(clippy::mutable_key_type)]
pub fn serialize<$($generic: serde::Serialize, )?S: serde::Serializer>(
val: &$seq,
ser: S,
Expand Down Expand Up @@ -220,7 +220,7 @@ macro_rules! serde_seq {
where
V: serde::de::SeqAccess<'de>,
{
#[allow(clippy::redundant_closure_call)]
#[allow(clippy::redundant_closure_call, clippy::mutable_key_type)]
let mut ret = $create(seq.size_hint().unwrap_or_default());
while let Some(val) = seq.next_element::<TempDe$(<$generic>)?>()? {
ret.$insert(val.0);
Expand Down
7 changes: 7 additions & 0 deletions src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ create_visitor!(Visitor, Type, EXPECT_MESSAGE, (visit_str, &str));
deserialize_str!(Visitor, Type);

derive_extension_types!(super::Type);
serde_seq!(
std::collections::HashSet<super::Type>,
super::Type,
std::collections::HashSet::with_capacity,
insert,
hash_set
);
7 changes: 7 additions & 0 deletions src/path_and_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ create_visitor!(
deserialize_string!(Visitor, Type);

derive_extension_types!(super::Type);
serde_seq!(
std::collections::HashSet<super::Type>,
super::Type,
std::collections::HashSet::with_capacity,
insert,
hash_set
);
7 changes: 7 additions & 0 deletions src/scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ create_visitor!(Visitor, Type, EXPECT_MESSAGE, (visit_str, &str));
deserialize_str!(Visitor, Type);

derive_extension_types!(super::Type);
serde_seq!(
std::collections::HashSet<super::Type>,
super::Type,
std::collections::HashSet::with_capacity,
insert,
hash_set
);
14 changes: 14 additions & 0 deletions src/status_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,17 @@ where
}

derive_extension_types!(super::Type);
serde_seq!(
std::collections::HashSet<super::Type>,
super::Type,
std::collections::HashSet::with_capacity,
insert,
hash_set
);
serde_seq!(
std::collections::BTreeSet<super::Type>,
super::Type,
|_| std::collections::BTreeSet::new(),
insert,
btree_set
);
7 changes: 7 additions & 0 deletions src/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ create_visitor!(
deserialize_string!(Visitor, Type);

derive_extension_types!(super::Type);
serde_seq!(
std::collections::HashSet<super::Type>,
super::Type,
std::collections::HashSet::with_capacity,
insert,
hash_set
);
14 changes: 14 additions & 0 deletions src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,17 @@ impl<'de> de::Visitor<'de> for Visitor {
deserialize_str!(Visitor, Type);

derive_extension_types!(super::Type);
serde_seq!(
std::collections::HashSet<super::Type>,
super::Type,
std::collections::HashSet::with_capacity,
insert,
hash_set
);
serde_seq!(
std::collections::BTreeSet<super::Type>,
super::Type,
|_| std::collections::BTreeSet::new(),
insert,
btree_set
);

0 comments on commit d141da8

Please sign in to comment.