From ffb1531e0e9810a746c3a3588394519ef1fdf221 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sun, 25 Jul 2021 11:50:31 +0800 Subject: [PATCH] New constants for Dynamic. --- CHANGELOG.md | 1 + src/dynamic.rs | 62 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2819836..98e4ad65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Enhancements * `$symbol$` is supported in custom syntax to match any symbol. * `Dynamic::as_string` and `Dynamic::as_immutable_string` are deprecated and replaced by `into_string` and `into_immutable_string` respectively. +* Added a number of constants to `Dynamic`. * `parse_float()`, `PI()` and `E()` now defer to `Decimal` under `no_float` if `decimal` is turned on. diff --git a/src/dynamic.rs b/src/dynamic.rs index 8d401697..b1126623 100644 --- a/src/dynamic.rs +++ b/src/dynamic.rs @@ -830,8 +830,14 @@ impl Dynamic { pub const ONE: Dynamic = Self(Union::Int(1, DEFAULT_TAG_VALUE, ReadWrite)); /// A [`Dynamic`] containing the integer two. pub const TWO: Dynamic = Self(Union::Int(2, DEFAULT_TAG_VALUE, ReadWrite)); + /// A [`Dynamic`] containing the integer three. + pub const THREE: Dynamic = Self(Union::Int(3, DEFAULT_TAG_VALUE, ReadWrite)); /// A [`Dynamic`] containing the integer ten. pub const TEN: Dynamic = Self(Union::Int(10, DEFAULT_TAG_VALUE, ReadWrite)); + /// A [`Dynamic`] containing the integer one hundred. + pub const HUNDRED: Dynamic = Self(Union::Int(100, DEFAULT_TAG_VALUE, ReadWrite)); + /// A [`Dynamic`] containing the integer one thousand. + pub const THOUSAND: Dynamic = Self(Union::Int(1000, DEFAULT_TAG_VALUE, ReadWrite)); /// A [`Dynamic`] containing the integer negative one. pub const NEGATIVE_ONE: Dynamic = Self(Union::Int(-1, DEFAULT_TAG_VALUE, ReadWrite)); /// A [`Dynamic`] containing `0.0`. @@ -870,7 +876,25 @@ impl Dynamic { DEFAULT_TAG_VALUE, ReadWrite, )); - /// A [`Dynamic`] containing the `-1.0`. + /// A [`Dynamic`] containing `100.0`. + /// + /// Not available under `no_float`. + #[cfg(not(feature = "no_float"))] + pub const FLOAT_HUNDRED: Dynamic = Self(Union::Float( + FloatWrapper::new_const(100.0), + DEFAULT_TAG_VALUE, + ReadWrite, + )); + /// A [`Dynamic`] containing `1000.0`. + /// + /// Not available under `no_float`. + #[cfg(not(feature = "no_float"))] + pub const FLOAT_THOUSAND: Dynamic = Self(Union::Float( + FloatWrapper::new_const(1000.0), + DEFAULT_TAG_VALUE, + ReadWrite, + )); + /// A [`Dynamic`] containing `-1.0`. /// /// Not available under `no_float`. #[cfg(not(feature = "no_float"))] @@ -879,6 +903,42 @@ impl Dynamic { DEFAULT_TAG_VALUE, ReadWrite, )); + /// A [`Dynamic`] containing π. + /// + /// Not available under `no_float`. + #[cfg(not(feature = "no_float"))] + pub const FLOAT_PI: Dynamic = Self(Union::Float( + #[cfg(not(feature = "f32_float"))] + FloatWrapper::new_const(std::f64::consts::PI), + #[cfg(feature = "f32_float")] + FloatWrapper::new_const(std::f32::consts::PI), + DEFAULT_TAG_VALUE, + ReadWrite, + )); + /// A [`Dynamic`] containing π/2. + /// + /// Not available under `no_float`. + #[cfg(not(feature = "no_float"))] + pub const FLOAT_HALF_PI: Dynamic = Self(Union::Float( + #[cfg(not(feature = "f32_float"))] + FloatWrapper::new_const(std::f64::consts::PI / 2.0), + #[cfg(feature = "f32_float")] + FloatWrapper::new_const(std::f32::consts::PI / 2.0), + DEFAULT_TAG_VALUE, + ReadWrite, + )); + /// A [`Dynamic`] containing 2π. + /// + /// Not available under `no_float`. + #[cfg(not(feature = "no_float"))] + pub const FLOAT_TWO_PI: Dynamic = Self(Union::Float( + #[cfg(not(feature = "f32_float"))] + FloatWrapper::new_const(2.0 * std::f64::consts::PI), + #[cfg(feature = "f32_float")] + FloatWrapper::new_const(2.0 * std::f32::consts::PI), + DEFAULT_TAG_VALUE, + ReadWrite, + )); /// Get the [`AccessMode`] for this [`Dynamic`]. #[must_use]