Skip to content

Commit 08c4dab

Browse files
committed
Implement Settings for Saturating<T> and NonZero<T>
In both cases, we need to add impls for specific instantiations because serde does not supply `Serialize`/`Deserialize` impls for the generic versions. (Those were added later to std.) Serde needs to be at least version `1.0.198`. Additionally, for `NonZero`, our impl only applies to `Option<NonZero<T>>` because `NonZero<T>` does not have a sensible default value. Resolves #161
1 parent 974a605 commit 08c4dab

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ regex = "1.8"
7373
reqwest = { version = "0.12", default-features = false }
7474
socket2 = { version = "0.5", features = ["all"] }
7575
syn = "2"
76-
serde = "1"
76+
serde = "1.0.198"
7777
serde_path_to_error = "0.1.17"
7878
serde_yaml = "0.8.26"
7979
serde_with = "3.3"

foundations/src/settings/basic_impls.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::ffi::{CString, OsString};
88
use std::fmt::Debug;
99
use std::hash::Hash;
1010
use std::marker::PhantomData;
11-
use std::num::Wrapping;
11+
use std::num::{NonZero, Saturating, Wrapping};
1212
use std::ops::Range;
1313
use std::path::PathBuf;
1414
use std::rc::Rc;
@@ -34,6 +34,20 @@ impl_noop!(<Idx> Settings for Range<Idx> where Idx: Debug + Serialize + Deserial
3434
impl_noop!(<T> Settings for Reverse<T> where T: Settings);
3535
impl_noop!(<T> Settings for Wrapping<T> where T: Settings);
3636

37+
// serde does not have generic impls for Saturating<T> and NonZero<T>
38+
macro_rules! impl_for_num {
39+
( $( $Ty:ty )* ) => { $(
40+
impl_noop!(Settings for $Ty);
41+
impl_noop!(Settings for Saturating<$Ty>);
42+
impl_noop!(Settings for Option<NonZero<$Ty>>);
43+
)* };
44+
}
45+
46+
impl_for_num! {
47+
i8 i16 i32 i64 i128 isize
48+
u8 u16 u32 u64 u128 usize
49+
}
50+
3751
macro_rules! impl_for_non_generic {
3852
( $( $Ty:ty ),* ) => {
3953
$( impl_noop!(Settings for $Ty); )*
@@ -45,18 +59,6 @@ impl_for_non_generic! {
4559
char,
4660
f32,
4761
f64,
48-
i128,
49-
i16,
50-
i32,
51-
i64,
52-
i8,
53-
isize,
54-
u128,
55-
u16,
56-
u32,
57-
u64,
58-
u8,
59-
usize,
6062
String,
6163
(),
6264
CString,

0 commit comments

Comments
 (0)