pub struct Temperature(/* private fields */);
Expand description

A temperature to use in simulation.

Methods from Deref<Target = Decimal>§

pub const MIN: Decimal = MIN

pub const MAX: Decimal = MAX

pub const ZERO: Decimal = ZERO

pub const ONE: Decimal = ONE

pub const NEGATIVE_ONE: Decimal = NEGATIVE_ONE

pub const TWO: Decimal = TWO

pub const TEN: Decimal = TEN

pub const ONE_HUNDRED: Decimal = ONE_HUNDRED

pub const ONE_THOUSAND: Decimal = ONE_THOUSAND

pub const PI: Decimal = _

pub const HALF_PI: Decimal = _

pub const QUARTER_PI: Decimal = _

pub const TWO_PI: Decimal = _

pub const E: Decimal = _

pub const E_INVERSE: Decimal = _

pub fn scale(&self) -> u32

Returns the scale of the decimal number, otherwise known as e.

§Example
let num = Decimal::new(1234, 3);
assert_eq!(num.scale(), 3u32);

pub fn mantissa(&self) -> i128

Returns the mantissa of the decimal number.

§Example
use rust_decimal_macros::dec;

let num = dec!(-1.2345678);
assert_eq!(num.mantissa(), -12345678i128);
assert_eq!(num.scale(), 7);

pub fn is_zero(&self) -> bool

Returns true if this Decimal number is equivalent to zero.

§Example
let num = Decimal::ZERO;
assert!(num.is_zero());

pub fn is_integer(&self) -> bool

Returns true if this Decimal number has zero fractional part (is equal to an integer)

§Example
assert_eq!(dec!(5).is_integer(), true);
// Trailing zeros are also ignored
assert_eq!(dec!(5.0000).is_integer(), true);
// If there is a fractional part then it is not an integer
assert_eq!(dec!(5.1).is_integer(), false);

pub fn set_sign(&mut self, positive: bool)

👎Deprecated since 1.4.0: please use set_sign_positive instead

An optimized method for changing the sign of a decimal number.

§Arguments
  • positive: true if the resulting decimal should be positive.
§Example
let mut one = Decimal::ONE;
one.set_sign(false);
assert_eq!(one.to_string(), "-1");

pub fn set_sign_positive(&mut self, positive: bool)

An optimized method for changing the sign of a decimal number.

§Arguments
  • positive: true if the resulting decimal should be positive.
§Example
let mut one = Decimal::ONE;
one.set_sign_positive(false);
assert_eq!(one.to_string(), "-1");

pub fn set_sign_negative(&mut self, negative: bool)

An optimized method for changing the sign of a decimal number.

§Arguments
  • negative: true if the resulting decimal should be negative.
§Example
let mut one = Decimal::ONE;
one.set_sign_negative(true);
assert_eq!(one.to_string(), "-1");

pub fn set_scale(&mut self, scale: u32) -> Result<(), Error>

An optimized method for changing the scale of a decimal number.

§Arguments
  • scale: the new scale of the number
§Example
let mut one = Decimal::ONE;
one.set_scale(5)?;
assert_eq!(one.to_string(), "0.00001");

pub fn rescale(&mut self, scale: u32)

Modifies the Decimal towards the desired scale, attempting to do so without changing the underlying number itself.

Setting the scale to something less then the current Decimals scale will cause the newly created Decimal to perform rounding using the MidpointAwayFromZero strategy.

Scales greater than the maximum precision that can be represented by Decimal will be automatically rounded to either Decimal::MAX_PRECISION or the maximum precision that can be represented with the given mantissa.

§Arguments
  • scale: The desired scale to use for the new Decimal number.
§Example
use rust_decimal_macros::dec;

// Rescaling to a higher scale preserves the value
let mut number = dec!(1.123);
assert_eq!(number.scale(), 3);
number.rescale(6);
assert_eq!(number.to_string(), "1.123000");
assert_eq!(number.scale(), 6);

// Rescaling to a lower scale forces the number to be rounded
let mut number = dec!(1.45);
assert_eq!(number.scale(), 2);
number.rescale(1);
assert_eq!(number.to_string(), "1.5");
assert_eq!(number.scale(), 1);

// This function never fails. Consequently, if a scale is provided that is unable to be
// represented using the given mantissa, then the maximum possible scale is used.
let mut number = dec!(11.76470588235294);
assert_eq!(number.scale(), 14);
number.rescale(28);
// A scale of 28 cannot be represented given this mantissa, however it was able to represent
// a number with a scale of 27
assert_eq!(number.to_string(), "11.764705882352940000000000000");
assert_eq!(number.scale(), 27);

pub fn serialize(&self) -> [u8; 16]

Returns a serialized version of the decimal number. The resulting byte array will have the following representation:

  • Bytes 1-4: flags
  • Bytes 5-8: lo portion of m
  • Bytes 9-12: mid portion of m
  • Bytes 13-16: high portion of m

pub fn is_negative(&self) -> bool

👎Deprecated since 0.6.3: please use is_sign_negative instead

Returns true if the decimal is negative.

pub fn is_positive(&self) -> bool

👎Deprecated since 0.6.3: please use is_sign_positive instead

Returns true if the decimal is positive.

pub fn is_sign_negative(&self) -> bool

Returns true if the sign bit of the decimal is negative.

§Example
assert_eq!(true, Decimal::new(-1, 0).is_sign_negative());
assert_eq!(false, Decimal::new(1, 0).is_sign_negative());

pub fn is_sign_positive(&self) -> bool

Returns true if the sign bit of the decimal is positive.

§Example
assert_eq!(false, Decimal::new(-1, 0).is_sign_positive());
assert_eq!(true, Decimal::new(1, 0).is_sign_positive());

pub fn trunc(&self) -> Decimal

Returns a new Decimal integral with no fractional portion. This is a true truncation whereby no rounding is performed.

§Example
let pi = dec!(3.141);
assert_eq!(pi.trunc(), dec!(3));

// Negative numbers are similarly truncated without rounding
let neg = dec!(-1.98765);
assert_eq!(neg.trunc(), Decimal::NEGATIVE_ONE);

pub fn trunc_with_scale(&self, scale: u32) -> Decimal

Returns a new Decimal with the fractional portion delimited by scale. This is a true truncation whereby no rounding is performed.

§Example
let pi = dec!(3.141592);
assert_eq!(pi.trunc_with_scale(2), dec!(3.14));

// Negative numbers are similarly truncated without rounding
let neg = dec!(-1.98765);
assert_eq!(neg.trunc_with_scale(1), dec!(-1.9));

pub fn fract(&self) -> Decimal

Returns a new Decimal representing the fractional portion of the number.

§Example
let pi = Decimal::new(3141, 3);
let fract = Decimal::new(141, 3);
// note that it returns a decimal
assert_eq!(pi.fract(), fract);

pub fn abs(&self) -> Decimal

Computes the absolute value of self.

§Example
let num = Decimal::new(-3141, 3);
assert_eq!(num.abs().to_string(), "3.141");

pub fn floor(&self) -> Decimal

Returns the largest integer less than or equal to a number.

§Example
let num = Decimal::new(3641, 3);
assert_eq!(num.floor().to_string(), "3");

pub fn ceil(&self) -> Decimal

Returns the smallest integer greater than or equal to a number.

§Example
let num = Decimal::new(3141, 3);
assert_eq!(num.ceil().to_string(), "4");
let num = Decimal::new(3, 0);
assert_eq!(num.ceil().to_string(), "3");

pub fn normalize(&self) -> Decimal

Strips any trailing zero’s from a Decimal and converts -0 to 0.

§Example
let number = Decimal::from_str("3.100")?;
assert_eq!(number.normalize().to_string(), "3.1");

pub fn normalize_assign(&mut self)

An in place version of normalize. Strips any trailing zero’s from a Decimal and converts -0 to 0.

§Example
let mut number = Decimal::from_str("3.100")?;
assert_eq!(number.to_string(), "3.100");
number.normalize_assign();
assert_eq!(number.to_string(), "3.1");

pub fn round(&self) -> Decimal

Returns a new Decimal number with no fractional portion (i.e. an integer). Rounding currently follows “Bankers Rounding” rules. e.g. 6.5 -> 6, 7.5 -> 8

§Example
// Demonstrating bankers rounding...
let number_down = Decimal::new(65, 1);
let number_up   = Decimal::new(75, 1);
assert_eq!(number_down.round().to_string(), "6");
assert_eq!(number_up.round().to_string(), "8");

pub fn round_dp_with_strategy( &self, dp: u32, strategy: RoundingStrategy ) -> Decimal

Returns a new Decimal number with the specified number of decimal points for fractional portion. Rounding is performed using the provided [RoundingStrategy]

§Arguments
  • dp: the number of decimal points to round to.
  • strategy: the [RoundingStrategy] to use.
§Example
let tax = dec!(3.4395);
assert_eq!(tax.round_dp_with_strategy(2, RoundingStrategy::MidpointAwayFromZero).to_string(), "3.44");

pub fn round_dp(&self, dp: u32) -> Decimal

Returns a new Decimal number with the specified number of decimal points for fractional portion. Rounding currently follows “Bankers Rounding” rules. e.g. 6.5 -> 6, 7.5 -> 8

§Arguments
  • dp: the number of decimal points to round to.
§Example
let pi = dec!(3.1415926535897932384626433832);
assert_eq!(pi.round_dp(2).to_string(), "3.14");

pub fn round_sf(&self, digits: u32) -> Option<Decimal>

Returns Some(Decimal) number rounded to the specified number of significant digits. If the resulting number is unable to be represented by the Decimal number then None will be returned. When the number of significant figures of the Decimal being rounded is greater than the requested number of significant digits then rounding will be performed using MidpointNearestEven strategy.

§Arguments
  • digits: the number of significant digits to round to.
§Remarks

A significant figure is determined using the following rules:

  1. Non-zero digits are always significant.
  2. Zeros between non-zero digits are always significant.
  3. Leading zeros are never significant.
  4. Trailing zeros are only significant if the number contains a decimal point.
§Example
use rust_decimal_macros::dec;

let value = dec!(305.459);
assert_eq!(value.round_sf(0), Some(dec!(0)));
assert_eq!(value.round_sf(1), Some(dec!(300)));
assert_eq!(value.round_sf(2), Some(dec!(310)));
assert_eq!(value.round_sf(3), Some(dec!(305)));
assert_eq!(value.round_sf(4), Some(dec!(305.5)));
assert_eq!(value.round_sf(5), Some(dec!(305.46)));
assert_eq!(value.round_sf(6), Some(dec!(305.459)));
assert_eq!(value.round_sf(7), Some(dec!(305.4590)));
assert_eq!(Decimal::MAX.round_sf(1), None);

let value = dec!(0.012301);
assert_eq!(value.round_sf(3), Some(dec!(0.0123)));

pub fn round_sf_with_strategy( &self, digits: u32, strategy: RoundingStrategy ) -> Option<Decimal>

Returns Some(Decimal) number rounded to the specified number of significant digits. If the resulting number is unable to be represented by the Decimal number then None will be returned. When the number of significant figures of the Decimal being rounded is greater than the requested number of significant digits then rounding will be performed using the provided [RoundingStrategy].

§Arguments
  • digits: the number of significant digits to round to.
  • strategy: if required, the rounding strategy to use.
§Remarks

A significant figure is determined using the following rules:

  1. Non-zero digits are always significant.
  2. Zeros between non-zero digits are always significant.
  3. Leading zeros are never significant.
  4. Trailing zeros are only significant if the number contains a decimal point.
§Example
use rust_decimal_macros::dec;

let value = dec!(305.459);
assert_eq!(value.round_sf_with_strategy(0, RoundingStrategy::ToZero), Some(dec!(0)));
assert_eq!(value.round_sf_with_strategy(1, RoundingStrategy::ToZero), Some(dec!(300)));
assert_eq!(value.round_sf_with_strategy(2, RoundingStrategy::ToZero), Some(dec!(300)));
assert_eq!(value.round_sf_with_strategy(3, RoundingStrategy::ToZero), Some(dec!(305)));
assert_eq!(value.round_sf_with_strategy(4, RoundingStrategy::ToZero), Some(dec!(305.4)));
assert_eq!(value.round_sf_with_strategy(5, RoundingStrategy::ToZero), Some(dec!(305.45)));
assert_eq!(value.round_sf_with_strategy(6, RoundingStrategy::ToZero), Some(dec!(305.459)));
assert_eq!(value.round_sf_with_strategy(7, RoundingStrategy::ToZero), Some(dec!(305.4590)));
assert_eq!(Decimal::MAX.round_sf_with_strategy(1, RoundingStrategy::ToZero), Some(dec!(70000000000000000000000000000)));

let value = dec!(0.012301);
assert_eq!(value.round_sf_with_strategy(3, RoundingStrategy::AwayFromZero), Some(dec!(0.0124)));

pub fn unpack(&self) -> UnpackedDecimal

Convert Decimal to an internal representation of the underlying struct. This is useful for debugging the internal state of the object.

§Important Disclaimer

This is primarily intended for library maintainers. The internal representation of a Decimal is considered “unstable” for public use.

§Example
use rust_decimal_macros::dec;

let pi = dec!(3.1415926535897932384626433832);
assert_eq!(format!("{:?}", pi), "3.1415926535897932384626433832");
assert_eq!(format!("{:?}", pi.unpack()), "UnpackedDecimal { \
    negative: false, scale: 28, hi: 1703060790, mid: 185874565, lo: 1102470952 \
}");

Trait Implementations§

source§

impl Deref for Temperature

§

type Target = Decimal

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for Temperature

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl From<Decimal> for Temperature

source§

fn from(value: Decimal) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CustomHardwareType<Flipped<T>> for U

source§

fn from_layout_type(other: &Flipped<T>) -> U

Creates this layout type from another layout type.
source§

impl<T, U> CustomHardwareType<InOut<T>> for U

source§

fn from_layout_type(other: &InOut<T>) -> U

Creates this layout type from another layout type.
source§

impl<T, U> CustomHardwareType<Input<T>> for U

source§

fn from_layout_type(other: &Input<T>) -> U

Creates this layout type from another layout type.
source§

impl<T, U> CustomHardwareType<Output<T>> for U

source§

fn from_layout_type(other: &Output<T>) -> U

Creates this layout type from another layout type.
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> Connect<&T> for T

source§

impl<T> Connect<T> for T

source§

impl<T> Primitive for T