Skip to content

Commit

Permalink
Remove any feature = "std" gating
Browse files Browse the repository at this point in the history
A `std` feature cannot yet be introduces, so these would otherwise break
the code.
  • Loading branch information
jonasbb committed May 12, 2022
1 parent c9d9226 commit 9e952e2
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 41 deletions.
2 changes: 0 additions & 2 deletions serde_with/src/de/const_arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::utils::{MapIter, SeqIter};
use alloc::{borrow::Cow, boxed::Box, collections::BTreeMap, string::String, vec::Vec};
use core::{convert::TryInto, fmt, mem::MaybeUninit};
use serde::de::*;
#[cfg(feature = "std")]
use std::collections::HashMap;

// TODO this should probably be moved into the utils module when const generics are available for MSRV
Expand Down Expand Up @@ -146,7 +145,6 @@ macro_rules! tuple_seq_as_map_impl_intern {
}
}
tuple_seq_as_map_impl_intern!([(K, V); N], BTreeMap<KAs, VAs>);
#[cfg(feature = "std")]
tuple_seq_as_map_impl_intern!([(K, V); N], HashMap<KAs, VAs>);

impl<'de, const N: usize> DeserializeAs<'de, [u8; N]> for Bytes {
Expand Down
14 changes: 1 addition & 13 deletions serde_with/src/de/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@ use alloc::{
sync::{Arc, Weak as ArcWeak},
vec::Vec,
};
#[cfg(any(feature = "indexmap", feature = "std"))]
use core::hash::{BuildHasher, Hash};
use core::{
cell::{Cell, RefCell},
convert::TryInto,
fmt::{self, Display},
hash::{BuildHasher, Hash},
iter::FromIterator,
str::FromStr,
time::Duration,
};
#[cfg(feature = "indexmap")]
use indexmap_crate::{IndexMap, IndexSet};
use serde::de::*;
#[cfg(feature = "std")]
use std::{
collections::{HashMap, HashSet},
sync::{Mutex, RwLock},
Expand Down Expand Up @@ -182,7 +180,6 @@ where
}
}

#[cfg(feature = "std")]
impl<'de, T, U> DeserializeAs<'de, Mutex<T>> for Mutex<U>
where
U: DeserializeAs<'de, T>,
Expand All @@ -197,7 +194,6 @@ where
}
}

#[cfg(feature = "std")]
impl<'de, T, U> DeserializeAs<'de, RwLock<T>> for RwLock<U>
where
U: DeserializeAs<'de, T>,
Expand Down Expand Up @@ -313,7 +309,6 @@ seq_impl!(
push
);
seq_impl!(BTreeSet<T: Ord>, seq, BTreeSet::new(), insert);
#[cfg(feature = "std")]
seq_impl!(
HashSet<T: Eq + Hash, S: BuildHasher + Default>,
seq,
Expand Down Expand Up @@ -407,7 +402,6 @@ map_impl!(
BTreeMap<K: Ord, V>,
map,
BTreeMap::new());
#[cfg(feature = "std")]
map_impl!(
HashMap<K: Eq + Hash, V, S: BuildHasher + Default>,
map,
Expand Down Expand Up @@ -537,7 +531,6 @@ macro_rules! map_as_tuple_seq {
};
}
map_as_tuple_seq!(BTreeMap<K: Ord, V>);
#[cfg(feature = "std")]
map_as_tuple_seq!(HashMap<K: Eq + Hash, V>);
#[cfg(feature = "indexmap")]
map_as_tuple_seq!(IndexMap<K: Eq + Hash, V>);
Expand Down Expand Up @@ -704,7 +697,6 @@ macro_rules! tuple_seq_as_map_impl_intern {
macro_rules! tuple_seq_as_map_impl {
($($tyorig:ident < (K $(: $($kbound:ident $(+)?)+)?, V $(: $($vbound:ident $(+)?)+)?)> $(,)?)+) => {$(
tuple_seq_as_map_impl_intern!($tyorig < (K $(: $($kbound +)+)?, V $(: $($vbound +)+)?) >, BTreeMap<KAs, VAs>);
#[cfg(feature = "std")]
tuple_seq_as_map_impl_intern!($tyorig < (K $(: $($kbound +)+)?, V $(: $($vbound +)+)?) >, HashMap<KAs, VAs>);
)+}
}
Expand All @@ -716,7 +708,6 @@ tuple_seq_as_map_impl! {
Vec<(K, V)>,
VecDeque<(K, V)>,
}
#[cfg(feature = "std")]
tuple_seq_as_map_impl!(HashSet<(K: Eq + Hash, V: Eq + Hash)>);
#[cfg(feature = "indexmap")]
tuple_seq_as_map_impl!(IndexSet<(K: Eq + Hash, V: Eq + Hash)>);
Expand Down Expand Up @@ -775,7 +766,6 @@ macro_rules! tuple_seq_as_map_option_impl {
)+}
}
tuple_seq_as_map_option_impl!(BTreeMap);
#[cfg(feature = "std")]
tuple_seq_as_map_option_impl!(HashMap);

impl<'de, T, TAs> DeserializeAs<'de, T> for DefaultOnError<TAs>
Expand Down Expand Up @@ -903,7 +893,6 @@ use_signed_duration!(
}
);

#[cfg(feature = "std")]
use_signed_duration!(
TimestampSeconds DurationSeconds,
TimestampMilliSeconds DurationMilliSeconds,
Expand All @@ -917,7 +906,6 @@ use_signed_duration!(
{FORMAT, Flexible => FORMAT: Format}
}
);
#[cfg(feature = "std")]
use_signed_duration!(
TimestampSecondsWithFrac DurationSecondsWithFrac,
TimestampMilliSecondsWithFrac DurationMilliSecondsWithFrac,
Expand Down
4 changes: 0 additions & 4 deletions serde_with/src/duplicate_key_impls/error_on_duplicate.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use alloc::collections::{BTreeMap, BTreeSet};
#[cfg(any(feature = "indexmap", feature = "std"))]
use core::hash::{BuildHasher, Hash};
#[cfg(feature = "indexmap")]
use indexmap_crate::{IndexMap, IndexSet};
#[cfg(feature = "std")]
use std::collections::{HashMap, HashSet};

pub trait PreventDuplicateInsertsSet<T> {
Expand All @@ -20,7 +18,6 @@ pub trait PreventDuplicateInsertsMap<K, V> {
fn insert(&mut self, key: K, value: V) -> bool;
}

#[cfg(feature = "std")]
impl<T, S> PreventDuplicateInsertsSet<T> for HashSet<T, S>
where
T: Eq + Hash,
Expand Down Expand Up @@ -75,7 +72,6 @@ where
}
}

#[cfg(feature = "std")]
impl<K, V, S> PreventDuplicateInsertsMap<K, V> for HashMap<K, V, S>
where
K: Eq + Hash,
Expand Down
4 changes: 0 additions & 4 deletions serde_with/src/duplicate_key_impls/first_value_wins.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use alloc::collections::{BTreeMap, BTreeSet};
#[cfg(any(feature = "indexmap", feature = "std"))]
use core::hash::{BuildHasher, Hash};
#[cfg(feature = "indexmap")]
use indexmap_crate::IndexMap;
#[cfg(feature = "std")]
use std::collections::{HashMap, HashSet};

#[deprecated = "This is serde's default behavior."]
Expand All @@ -21,7 +19,6 @@ pub trait DuplicateInsertsFirstWinsMap<K, V> {
fn insert(&mut self, key: K, value: V);
}

#[cfg(feature = "std")]
#[allow(deprecated)]
impl<T, S> DuplicateInsertsFirstWinsSet<T> for HashSet<T, S>
where
Expand Down Expand Up @@ -60,7 +57,6 @@ where
}
}

#[cfg(feature = "std")]
impl<K, V, S> DuplicateInsertsFirstWinsMap<K, V> for HashMap<K, V, S>
where
K: Eq + Hash,
Expand Down
3 changes: 0 additions & 3 deletions serde_with/src/duplicate_key_impls/last_value_wins.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use alloc::collections::BTreeSet;
#[cfg(any(feature = "indexmap", feature = "std"))]
use core::hash::{BuildHasher, Hash};
#[cfg(feature = "indexmap")]
use indexmap_crate::IndexSet;
#[cfg(feature = "std")]
use std::collections::HashSet;

pub trait DuplicateInsertsLastWinsSet<T> {
Expand All @@ -13,7 +11,6 @@ pub trait DuplicateInsertsLastWinsSet<T> {
fn replace(&mut self, value: T);
}

#[cfg(feature = "std")]
impl<T, S> DuplicateInsertsLastWinsSet<T> for HashSet<T, S>
where
T: Eq + Hash,
Expand Down
2 changes: 0 additions & 2 deletions serde_with/src/ser/const_arrays.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::*;
use alloc::{borrow::Cow, boxed::Box, collections::BTreeMap};
#[cfg(feature = "std")]
use std::collections::HashMap;

impl<T, As, const N: usize> SerializeAs<[T; N]> for [As; N]
Expand Down Expand Up @@ -43,7 +42,6 @@ macro_rules! tuple_seq_as_map_impl_intern {
};
}
tuple_seq_as_map_impl_intern!([(K, V); N], BTreeMap<K, V>);
#[cfg(feature = "std")]
tuple_seq_as_map_impl_intern!([(K, V); N], HashMap<K, V>);

impl<const N: usize> SerializeAs<[u8; N]> for Bytes {
Expand Down
10 changes: 0 additions & 10 deletions serde_with/src/ser/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use core::{
#[cfg(feature = "indexmap")]
use indexmap_crate::{IndexMap, IndexSet};
use serde::ser::Error;
#[cfg(feature = "std")]
use std::{
collections::{HashMap, HashSet},
sync::{Mutex, RwLock},
Expand Down Expand Up @@ -163,7 +162,6 @@ where
}
}

#[cfg(feature = "std")]
impl<T, U> SerializeAs<Mutex<T>> for Mutex<U>
where
U: SerializeAs<T>,
Expand All @@ -179,7 +177,6 @@ where
}
}

#[cfg(feature = "std")]
impl<T, U> SerializeAs<RwLock<T>> for RwLock<U>
where
U: SerializeAs<T>,
Expand Down Expand Up @@ -239,7 +236,6 @@ type Slice<T> = [T];
seq_impl!(BinaryHeap<T>);
seq_impl!(BoxedSlice<T>);
seq_impl!(BTreeSet<T>);
#[cfg(feature = "std")]
seq_impl!(HashSet<T, H: Sized>);
seq_impl!(LinkedList<T>);
seq_impl!(Slice<T>);
Expand Down Expand Up @@ -268,7 +264,6 @@ macro_rules! map_impl {
}

map_impl!(BTreeMap<K, V>);
#[cfg(feature = "std")]
map_impl!(HashMap<K, V, H: Sized>);
#[cfg(feature = "indexmap")]
map_impl!(IndexMap<K, V, H: Sized>);
Expand Down Expand Up @@ -334,7 +329,6 @@ macro_rules! map_as_tuple_seq {
}
map_as_tuple_seq!(BTreeMap<K, V>);
// TODO HashMap with a custom hasher support would be better, but results in "unconstrained type parameter"
#[cfg(feature = "std")]
map_as_tuple_seq!(HashMap<K, V>);
#[cfg(feature = "indexmap")]
map_as_tuple_seq!(IndexMap<K, V>);
Expand Down Expand Up @@ -416,7 +410,6 @@ macro_rules! tuple_seq_as_map_impl_intern {
macro_rules! tuple_seq_as_map_impl {
($($ty:ty $(,)?)+) => {$(
tuple_seq_as_map_impl_intern!($ty, BTreeMap<K, V>);
#[cfg(feature = "std")]
tuple_seq_as_map_impl_intern!($ty, HashMap<K, V>);
)+}
}
Expand All @@ -429,7 +422,6 @@ tuple_seq_as_map_impl! {
Vec<(K, V)>,
VecDeque<(K, V)>,
}
#[cfg(feature = "std")]
tuple_seq_as_map_impl!(HashSet<(K, V)>);
#[cfg(feature = "indexmap")]
tuple_seq_as_map_impl!(IndexSet<(K, V)>);
Expand Down Expand Up @@ -538,7 +530,6 @@ use_signed_duration!(
}
);

#[cfg(feature = "std")]
use_signed_duration!(
TimestampSeconds DurationSeconds,
TimestampMilliSeconds DurationMilliSeconds,
Expand All @@ -551,7 +542,6 @@ use_signed_duration!(
{String, STRICTNESS => STRICTNESS: Strictness}
}
);
#[cfg(feature = "std")]
use_signed_duration!(
TimestampSecondsWithFrac DurationSecondsWithFrac,
TimestampMilliSecondsWithFrac DurationMilliSecondsWithFrac,
Expand Down
3 changes: 0 additions & 3 deletions serde_with/src/utils/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use serde::{
de::{self, Unexpected, Visitor},
ser, Deserialize, Deserializer, Serialize, Serializer,
};
#[cfg(feature = "std")]
use std::time::SystemTime;

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -66,7 +65,6 @@ impl DurationSigned {
Self { sign, duration }
}

#[cfg(feature = "std")]
pub(crate) fn to_system_time<'de, D>(self) -> Result<SystemTime, D::Error>
where
D: Deserializer<'de>,
Expand Down Expand Up @@ -100,7 +98,6 @@ impl From<&Duration> for DurationSigned {
}
}

#[cfg(feature = "std")]
impl From<&SystemTime> for DurationSigned {
fn from(time: &SystemTime) -> Self {
match time.duration_since(SystemTime::UNIX_EPOCH) {
Expand Down

0 comments on commit 9e952e2

Please sign in to comment.