Skip to content

Commit

Permalink
Change name of serde feature to more-serde, +numerical-traits
Browse files Browse the repository at this point in the history
this is a semver break
  • Loading branch information
ctrlcctrlv committed Jan 1, 2023
1 parent 0244fb9 commit e3b7646
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ cfg-if = "1.0"
cargo-emit = "0.2"
indoc = "1.0"

[dev-dependencies]
serde_json = "1.0"

[features]
hash = []
default = ["serde", "serde/std", "serde/default", "float-cmp", "float-cmp/std", "num-traits", "num-traits/std"]
numerical-traits = ["float-cmp", "float-cmp/std", "num-traits", "num-traits/std"]
more-serde = ["serde", "serde/std", "serde/default"]
default = ["numerical-traits"]
fat = ["more-serde", "default"]
x64-backing-store = []

hash = []
ignore_no_std_tests_check = []
5 changes: 4 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ fn main() {
} else {
rustc_cfg!("std");
}
if cfg!(any(feature = "serde", feature = "default")) {
if cfg!(any(feature = "more-serde", feature = "default")) {
rustc_cfg!("use_serde");
}
if cfg!(any(feature = "numerical-traits", feature = "default")) {
rustc_cfg!("numerical_traits");
}
if cfg!(feature = "hash") {
rustc_cfg!("with_impl_hash");
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub use str_conv::ConversionError;
/// A generic container for an "integer or a float".
///
/// Was made originally for the UFO data type "integer or float".
#[cfg_attr(use_serde, derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "more-serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone)]
pub enum IntegerOrFloat {
Integer(i_iof),
Expand Down
13 changes: 6 additions & 7 deletions src/num_traits_impl/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use super::IntegerOrFloat::{self, *};
use crate::f_iof;

use num_traits;
use num_traits::{cast::ToPrimitive, Zero, One, NumCast};

mod float;

#[cfg(feature = "num-traits")]
impl num_traits::cast::ToPrimitive for IntegerOrFloat {
impl ToPrimitive for IntegerOrFloat {
fn to_u64(&self) -> Option<u64> {
match self {
Integer(i) => i.to_u64(),
Expand All @@ -21,7 +20,7 @@ impl num_traits::cast::ToPrimitive for IntegerOrFloat {
}
}

impl num_traits::Zero for IntegerOrFloat {
impl Zero for IntegerOrFloat {
fn zero() -> Self {
Integer(0)
}
Expand All @@ -30,7 +29,7 @@ impl num_traits::Zero for IntegerOrFloat {
}
}

impl num_traits::One for IntegerOrFloat {
impl One for IntegerOrFloat {
fn one() -> Self {
Integer(1)
}
Expand All @@ -39,8 +38,8 @@ impl num_traits::One for IntegerOrFloat {
}
}

impl num_traits::NumCast for IntegerOrFloat {
fn from<N: num_traits::ToPrimitive>(num: N) -> Option<IntegerOrFloat> {
impl NumCast for IntegerOrFloat {
fn from<N: ToPrimitive>(num: N) -> Option<IntegerOrFloat> {
num.to_f64().map(|n| IntegerOrFloat::Float(n as f_iof))
}
}
4 changes: 2 additions & 2 deletions src/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{f_iof, i_iof};
/// A generic container for a "negative integer or a float".
///
/// Was made originally for the UFO data type "negative integer or float".
#[cfg_attr(use_serde, derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "more-serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Display, Debug, Deref, DerefMut, AsRef, AsMut)]
#[display(fmt = "{}", inner)]
pub struct Negative {
Expand All @@ -23,7 +23,7 @@ impl Negative {
}

/// A generic container for a "positive integer or a float".
#[cfg_attr(use_serde, derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "more-serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Display, Debug, Deref, DerefMut, AsRef, AsMut)]
#[display(fmt = "{}", inner)]
pub struct Positive {
Expand Down

0 comments on commit e3b7646

Please sign in to comment.