diff --git a/Cargo.toml b/Cargo.toml index a1cce0e..b4b554c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,6 +82,8 @@ test-util = ["num-traits/std"] extra-postgres = ["num-traits"] extra-postgres-encode = ["extra-postgres", "bytes", "byteorder"] +debug_display = [] + [profile.release] lto = true # enable link-time optimization for faster runtime, but slower compile time opt-level = 3 # maximum optimization level for faster runtime, but slower compile time diff --git a/examples/debug_display/Cargo.toml b/examples/debug_display/Cargo.toml new file mode 100644 index 0000000..06c5ceb --- /dev/null +++ b/examples/debug_display/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "debug_display" +version = "0.0.1" +authors = ["Neo"] +edition = "2021" +license = "MIT OR Apache-2.0" + +[dependencies] +fastnum = { path = "../../", features = ["debug_display"] } \ No newline at end of file diff --git a/examples/debug_display/src/main.rs b/examples/debug_display/src/main.rs new file mode 100644 index 0000000..d39389b --- /dev/null +++ b/examples/debug_display/src/main.rs @@ -0,0 +1,6 @@ +use fastnum::*; + +fn main() { + assert_eq!(format!("{:?}", D128::from(1)), "1".to_string()); + assert_eq!(format!("{:?}", D128::parse_str("0.002", decimal::Context::default())), "0.002".to_string()); +} \ No newline at end of file diff --git a/src/decimal/dec/impls/fmt.rs b/src/decimal/dec/impls/fmt.rs index b25dc09..015703a 100644 --- a/src/decimal/dec/impls/fmt.rs +++ b/src/decimal/dec/impls/fmt.rs @@ -1,6 +1,6 @@ use core::fmt::{self, Debug, Display, Formatter, LowerExp, UpperExp}; -use crate::decimal::{dec::format, utils, Decimal}; +use crate::decimal::{dec::format, Decimal}; impl Display for Decimal { #[inline] @@ -48,6 +48,14 @@ impl UpperExp for Decimal { impl Debug for Decimal { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - utils::fmt::debug_print(&self.digits, &self.cb, Self::type_name(), f) + #[cfg(not(feature = "debug_display"))] + { + crate::decimal::utils::fmt::debug_print(&self.digits, &self.cb, Self::type_name(), f) + } + + #[cfg(feature = "debug_display")] + { + write!(f, "{}", self) + } } }