Skip to content

Commit

Permalink
Use rustversion for conditional compilation
Browse files Browse the repository at this point in the history
Because `std::num::Saturating` is only available
since Rust 1.74.
  • Loading branch information
Jörn Bethune committed Mar 27, 2024
1 parent fd28d64 commit 86c01cc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions serde/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rust-version = "1.31"

[dependencies]
serde_derive = { version = "1", optional = true, path = "../serde_derive" }
rustversion = "1.0"

[dev-dependencies]
serde_derive = { version = "1", path = "../serde_derive" }
Expand Down
2 changes: 2 additions & 0 deletions serde/src/de/impls.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::lib::*;
use rustversion;

use crate::de::{
Deserialize, Deserializer, EnumAccess, Error, MapAccess, SeqAccess, Unexpected, VariantAccess,
Expand Down Expand Up @@ -3004,6 +3005,7 @@ where
}
}

#[rustversion::since(1.74)]
impl<'de, T> Deserialize<'de> for Saturating<T>
where
T: Deserialize<'de>,
Expand Down
4 changes: 3 additions & 1 deletion serde/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ mod lib {
pub use self::core::default;
pub use self::core::fmt::{self, Debug, Display, Write as FmtWrite};
pub use self::core::marker::{self, PhantomData};
pub use self::core::num::Saturating;
pub use self::core::num::Wrapping;
pub use self::core::ops::{Bound, Range, RangeFrom, RangeInclusive, RangeTo};
pub use self::core::option;
Expand Down Expand Up @@ -275,6 +274,9 @@ mod lib {
pub use std::sync::atomic::{AtomicI64, AtomicU64};
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "ptr"))]
pub use std::sync::atomic::{AtomicIsize, AtomicUsize};

#[rustversion::since(1.74)]
pub use self::core::num::Saturating;
}

// None of this crate's error handling needs the `From::from` error conversion
Expand Down
1 change: 1 addition & 0 deletions serde/src/ser/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,7 @@ where
}
}

#[rustversion::since(1.74)]
impl<T> Serialize for Saturating<T>
where
T: Serialize,
Expand Down

0 comments on commit 86c01cc

Please sign in to comment.