Skip to main content

PositiveRealScalar

Struct PositiveRealScalar 

Source
pub struct PositiveRealScalar<RealType: RealScalar>(/* private fields */);
Expand description

Type-safe wrapper for strictly positive real scalar values.

PositiveRealScalar<T> guarantees that wrapped values are strictly greater than zero. Zero is not valid for this type. For values that can be zero, use NonNegativeRealScalar.

§Mathematical Definition

PositiveRealScalar<T> = { x ∈ T : x > 0 }

This is the set of positive real numbers ℝ⁺, which excludes zero.

§Use Cases

  • Lengths and distances that cannot be zero
  • Positive tolerances
  • Scaling factors that must be positive
  • Any quantity that is mathematically required to be > 0

§Examples

§Basic Usage

use num_valid::scalars::{PositiveRealScalar, ErrorsPositiveRealScalar};
use try_create::TryNew;

// Valid positive values
let length = PositiveRealScalar::try_new(2.5_f64).unwrap();
let tiny = PositiveRealScalar::try_new(f64::MIN_POSITIVE).unwrap();

// Zero is NOT positive
assert!(matches!(
    PositiveRealScalar::try_new(0.0_f64),
    Err(ErrorsPositiveRealScalar::ZeroValue { .. })
));

// Negative values rejected
assert!(matches!(
    PositiveRealScalar::try_new(-1.0_f64),
    Err(ErrorsPositiveRealScalar::NegativeValue { .. })
));

§Difference from NonNegativeRealScalar

use num_valid::scalars::{PositiveRealScalar, NonNegativeRealScalar};
use try_create::TryNew;

// Zero is INVALID for PositiveRealScalar (x > 0)
assert!(PositiveRealScalar::try_new(0.0_f64).is_err());

// Zero is VALID for NonNegativeRealScalar (x ≥ 0)
assert!(NonNegativeRealScalar::try_new(0.0_f64).is_ok());

§Algebraic and Ordering Operations

PositiveRealScalar supports:

  • Addition: Sum of positive values is positive
  • Multiplication: Product of positive values is positive
  • Integer powers: Raising positive to any integer exponent yields positive
  • Square root: Preserves positivity (√x > 0 if x > 0)
  • Multiplicative identity (One): For neutral multiplication operations
  • Comparison (Max, Min): Ordering and selection helpers
use num::One;
use num_valid::{
    *,
    functions::{Max, Min, Pow},
    scalars::PositiveRealScalar,
};
use try_create::{IntoInner, TryNew};

let a = PositiveRealScalar::try_new(2.0_f64).unwrap();
let b = PositiveRealScalar::try_new(3.0_f64).unwrap();

// Add preserves positivity for valid operands.
let sum = a.clone() + b.clone();
assert_eq!(*sum.as_raw_scalar_ref(), 5.0);

// Multiply preserves positivity
let product = a.clone() * b.clone();
assert_eq!(*product.as_raw_scalar_ref(), 6.0);

// Integer powers preserve positivity
let squared = a.clone().pow(2u32);
assert_eq!(*squared.as_raw_scalar_ref(), 4.0);

// Square root preserves positivity
let sqrt = PositiveRealScalar::try_new(4.0_f64).unwrap().sqrt();
assert_eq!(*sqrt.as_raw_scalar_ref(), 2.0);

// One is the multiplicative identity.
let one = PositiveRealScalar::<f64>::one();
let result = a.clone() * one;
assert_eq!(*result.as_raw_scalar_ref(), 2.0);

let x = PositiveRealScalar::try_new(1.0_f64).unwrap();
let y = PositiveRealScalar::try_new(3.0_f64).unwrap();
assert_eq!(*Max::max_by_ref(&x, &y).as_raw_scalar_ref(), 3.0);
assert_eq!(*Min::min_by_value(x, y).as_raw_scalar_ref(), 1.0);

Implementations§

Source§

impl<RealType: RealScalar> PositiveRealScalar<RealType>

Source

pub fn into_inner(self) -> RealType

Consumes the struct and returns the inner value.

Source§

impl<RealType: RealScalar> PositiveRealScalar<RealType>

Source

pub fn sqrt(self) -> Self

Computes the square root of this positive scalar.

Since the input is guaranteed to be positive, the result is always defined and remains positive.

§Examples
use num_valid::{*, scalars::PositiveRealScalar};
use try_create::TryNew;

let value = PositiveRealScalar::try_new(4.0_f64).unwrap();
let sqrt = value.sqrt();
assert_eq!(sqrt.as_raw_scalar_ref(), &2.0);
Source

pub fn new(value: RealType) -> Self

Trait Implementations§

Source§

impl<RealType: RealScalar> Add for PositiveRealScalar<RealType>

Implements additive composition for PositiveRealScalar.

Since both operands are guaranteed to be positive, their sum is also positive.

Source§

type Output = PositiveRealScalar<RealType>

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
Source§

impl<'a, RealType: RealScalar> Add<&'a NonNegativeRealScalar<RealType>> for PositiveRealScalar<RealType>

Adds a NonNegativeRealScalar by reference to a PositiveRealScalar, yielding a PositiveRealScalar.

Since self is strictly positive (x > 0) and other is non-negative (y ≥ 0), their sum is strictly positive: x + y > 0.

Source§

type Output = PositiveRealScalar<RealType>

The resulting type after applying the + operator.
Source§

fn add( self, other: &'a NonNegativeRealScalar<RealType>, ) -> PositiveRealScalar<RealType>

Performs the + operation. Read more
Source§

impl<'a, RealType: RealScalar> Add<&'a PositiveRealScalar<RealType>> for PositiveRealScalar<RealType>

Implements reference-based addition for PositiveRealScalar.

This allows adding a reference to a positive scalar without consuming it. Since both operands are guaranteed to be positive, their sum is also positive.

Source§

type Output = PositiveRealScalar<RealType>

The resulting type after applying the + operator.
Source§

fn add( self, other: &'a PositiveRealScalar<RealType>, ) -> PositiveRealScalar<RealType>

Performs the + operation. Read more
Source§

impl<'a, RealType: RealScalar> Add<&'a PositiveRealScalar<RealType>> for NonNegativeRealScalar<RealType>

Adds a PositiveRealScalar by reference to a NonNegativeRealScalar, yielding a PositiveRealScalar.

Since other is strictly positive (x > 0) and self is non-negative (y ≥ 0), their sum is strictly positive: x + y > 0.

Source§

type Output = PositiveRealScalar<RealType>

The resulting type after applying the + operator.
Source§

fn add( self, other: &'a PositiveRealScalar<RealType>, ) -> PositiveRealScalar<RealType>

Performs the + operation. Read more
Source§

impl<RealType: RealScalar> Add<NonNegativeRealScalar<RealType>> for PositiveRealScalar<RealType>

Since self is strictly positive (x > 0) and other is non-negative (y ≥ 0), their sum is strictly positive: x + y > 0.

§Examples

use num_valid::{*, scalars::*};
use try_create::TryNew;

let pos = PositiveRealScalar::try_new(2.0_f64).unwrap();
let non_neg = NonNegativeRealScalar::try_new(3.0_f64).unwrap();

let result: PositiveRealScalar<f64> = pos + non_neg;
assert_eq!(result.as_raw_scalar_ref(), &5.0);
Source§

type Output = PositiveRealScalar<RealType>

The resulting type after applying the + operator.
Source§

fn add( self, other: NonNegativeRealScalar<RealType>, ) -> PositiveRealScalar<RealType>

Performs the + operation. Read more
Source§

impl<RealType: RealScalar> Add<PositiveRealScalar<RealType>> for NonNegativeRealScalar<RealType>

Since other is strictly positive (x > 0) and self is non-negative (y ≥ 0), their sum is strictly positive: x + y > 0.

§Examples

use num_valid::{*, scalars::*};
use try_create::TryNew;

let non_neg = NonNegativeRealScalar::try_new(0.0_f64).unwrap(); // zero!
let pos = PositiveRealScalar::try_new(5.0_f64).unwrap();

let result: PositiveRealScalar<f64> = non_neg + pos;
assert_eq!(result.as_raw_scalar_ref(), &5.0);
Source§

type Output = PositiveRealScalar<RealType>

The resulting type after applying the + operator.
Source§

fn add( self, other: PositiveRealScalar<RealType>, ) -> PositiveRealScalar<RealType>

Performs the + operation. Read more
Source§

impl<RealType: RealScalar> AddAssign for PositiveRealScalar<RealType>

Implements in-place addition for PositiveRealScalar by value.

This allows adding a positive scalar value to self.

Source§

fn add_assign(&mut self, other: PositiveRealScalar<RealType>)

Performs the += operation. Read more
Source§

impl<'a, RealType: RealScalar> AddAssign<&'a PositiveRealScalar<RealType>> for PositiveRealScalar<RealType>

Implements in-place reference-based addition for PositiveRealScalar.

This allows adding a reference to a positive scalar to self without consuming self.

Source§

fn add_assign(&mut self, other: &'a PositiveRealScalar<RealType>)

Performs the += operation. Read more
Source§

impl<RealType: RealScalar> AsRef<RealType> for PositiveRealScalar<RealType>

Source§

fn as_ref(&self) -> &RealType

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<RealType: Clone + RealScalar> Clone for PositiveRealScalar<RealType>

Source§

fn clone(&self) -> PositiveRealScalar<RealType>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<RealType: Debug + RealScalar> Debug for PositiveRealScalar<RealType>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, RealType> Deserialize<'de> for PositiveRealScalar<RealType>
where RealType: for<'a> Deserialize<'a> + RealScalar,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<RealType> Display for PositiveRealScalar<RealType>
where RealType: Display + RealScalar,

Source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<RealType: RealScalar> From<PositiveRealScalar<RealType>> for NonNegativeRealScalar<RealType>

This conversion is mathematically valid because every positive number (x > 0) is also non-negative (x ≥ 0). The conversion is infallible and zero-cost.

§Examples

use num_valid::{*, scalars::*};
use try_create::TryNew;

let positive = PositiveRealScalar::try_new(5.0_f64).unwrap();
let non_negative: NonNegativeRealScalar<f64> = positive.into();

assert_eq!(non_negative.as_raw_scalar_ref(), &5.0);
Source§

fn from(positive: PositiveRealScalar<RealType>) -> Self

Converts to this type from the input type.
Source§

impl<RealType: RealScalar> IntoInner for PositiveRealScalar<RealType>

Source§

fn into_inner(self) -> Self::InnerType

Consumes the struct and returns the inner value.

Source§

type InnerType = RealType

The type of the inner value that will be extracted.
Source§

impl<RealType: RealScalar> Max for PositiveRealScalar<RealType>

Implements Max for PositiveRealScalar.

Maximum selection is delegated to the default trait behavior based on PartialOrd.

Source§

fn max_by_ref<'a>(&'a self, other: &'a Self) -> &'a Self

Returns a reference to the maximum of self and other. Read more
Source§

fn max_by_value(self, other: Self) -> Self

Returns the maximum of self and other, consuming both values. Read more
Source§

impl<RealType: RealScalar> Min for PositiveRealScalar<RealType>

Implements Min for PositiveRealScalar.

Minimum selection is delegated to the default trait behavior based on PartialOrd.

Source§

fn min_by_ref<'a>(&'a self, other: &'a Self) -> &'a Self

Returns a reference to the minimum of self and other. Read more
Source§

fn min_by_value(self, other: Self) -> Self

Returns the minimum of self and other, consuming both values. Read more
Source§

impl<RealType: RealScalar> Mul for PositiveRealScalar<RealType>

Implements multiplicative composition for PositiveRealScalar.

Since both operands are guaranteed to be positive, their product is also positive.

Source§

type Output = PositiveRealScalar<RealType>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Self) -> Self

Performs the * operation. Read more
Source§

impl<'a, RealType: RealScalar> Mul<&'a PositiveRealScalar<RealType>> for PositiveRealScalar<RealType>

Implements reference-based multiplication for PositiveRealScalar.

This allows multiplying a positive scalar by a reference to another positive scalar without consuming it. Since both operands are guaranteed to be positive, their product is also positive.

Source§

type Output = PositiveRealScalar<RealType>

The resulting type after applying the * operator.
Source§

fn mul( self, other: &'a PositiveRealScalar<RealType>, ) -> PositiveRealScalar<RealType>

Performs the * operation. Read more
Source§

impl<RealType: RealScalar> MulAssign for PositiveRealScalar<RealType>

Implements in-place multiplication for PositiveRealScalar by value.

This allows multiplying self by a positive scalar value.

Source§

fn mul_assign(&mut self, other: PositiveRealScalar<RealType>)

Performs the *= operation. Read more
Source§

impl<'a, RealType: RealScalar> MulAssign<&'a PositiveRealScalar<RealType>> for PositiveRealScalar<RealType>

Implements in-place reference-based multiplication for PositiveRealScalar.

This allows multiplying self by a reference to another positive scalar without consuming self.

Source§

fn mul_assign(&mut self, other: &'a PositiveRealScalar<RealType>)

Performs the *= operation. Read more
Source§

impl<RealType: RealScalar> NeumaierAddable for PositiveRealScalar<RealType>

Implements Neumaier compensated summation for PositiveRealScalar.

This implementation delegates to the underlying real scalar type’s Neumaier compensated sum operation, preserving numerical stability for sums of positive values.

Source§

fn neumaier_compensated_sum( value: Self, sum: &mut Self, compensation: &mut Self, )

Performs one step of the Neumaier compensated summation algorithm. Read more
Source§

impl<RealType: RealScalar> One for PositiveRealScalar<RealType>

Source§

fn one() -> Self

Returns the multiplicative identity element of Self, 1. Read more
Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
Source§

impl<RealType: PartialEq + RealScalar> PartialEq for PositiveRealScalar<RealType>

Source§

fn eq(&self, other: &PositiveRealScalar<RealType>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<RealType: PartialOrd + RealScalar> PartialOrd for PositiveRealScalar<RealType>

Source§

fn partial_cmp(&self, other: &PositiveRealScalar<RealType>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<RealType: RealScalar> Pow<i8> for PositiveRealScalar<RealType>

Source§

fn pow(self, exponent: i8) -> Self

Raises the number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, i8>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>

The error type that can be returned by the try_pow method. This type must implement std::error::Error for proper error handling.
Source§

fn try_pow(self, exponent: i8) -> Result<Self, Self::Error>

Attempts to compute self (the base) raised to the power of exponent. Read more
Source§

impl<RealType: RealScalar> Pow<i16> for PositiveRealScalar<RealType>

Source§

fn pow(self, exponent: i16) -> Self

Raises the number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, i16>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>

The error type that can be returned by the try_pow method. This type must implement std::error::Error for proper error handling.
Source§

fn try_pow(self, exponent: i16) -> Result<Self, Self::Error>

Attempts to compute self (the base) raised to the power of exponent. Read more
Source§

impl<RealType: RealScalar> Pow<i32> for PositiveRealScalar<RealType>

Source§

fn pow(self, exponent: i32) -> Self

Raises the number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, i32>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>

The error type that can be returned by the try_pow method. This type must implement std::error::Error for proper error handling.
Source§

fn try_pow(self, exponent: i32) -> Result<Self, Self::Error>

Attempts to compute self (the base) raised to the power of exponent. Read more
Source§

impl<RealType: RealScalar> Pow<i64> for PositiveRealScalar<RealType>

Source§

fn pow(self, exponent: i64) -> Self

Raises the number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, i64>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>

The error type that can be returned by the try_pow method. This type must implement std::error::Error for proper error handling.
Source§

fn try_pow(self, exponent: i64) -> Result<Self, Self::Error>

Attempts to compute self (the base) raised to the power of exponent. Read more
Source§

impl<RealType: RealScalar> Pow<i128> for PositiveRealScalar<RealType>

Source§

fn pow(self, exponent: i128) -> Self

Raises the number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, i128>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>

The error type that can be returned by the try_pow method. This type must implement std::error::Error for proper error handling.
Source§

fn try_pow(self, exponent: i128) -> Result<Self, Self::Error>

Attempts to compute self (the base) raised to the power of exponent. Read more
Source§

impl<RealType: RealScalar> Pow<isize> for PositiveRealScalar<RealType>

Source§

fn pow(self, exponent: isize) -> Self

Raises the number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, isize>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>

The error type that can be returned by the try_pow method. This type must implement std::error::Error for proper error handling.
Source§

fn try_pow(self, exponent: isize) -> Result<Self, Self::Error>

Attempts to compute self (the base) raised to the power of exponent. Read more
Source§

impl<RealType: RealScalar> Pow<u8> for PositiveRealScalar<RealType>

Source§

fn pow(self, exponent: u8) -> Self

Raises the number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, u8>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>

The error type that can be returned by the try_pow method. This type must implement std::error::Error for proper error handling.
Source§

fn try_pow(self, exponent: u8) -> Result<Self, Self::Error>

Attempts to compute self (the base) raised to the power of exponent. Read more
Source§

impl<RealType: RealScalar> Pow<u16> for PositiveRealScalar<RealType>

Source§

fn pow(self, exponent: u16) -> Self

Raises the number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, u16>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>

The error type that can be returned by the try_pow method. This type must implement std::error::Error for proper error handling.
Source§

fn try_pow(self, exponent: u16) -> Result<Self, Self::Error>

Attempts to compute self (the base) raised to the power of exponent. Read more
Source§

impl<RealType: RealScalar> Pow<u32> for PositiveRealScalar<RealType>

Source§

fn pow(self, exponent: u32) -> Self

Raises the number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, u32>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>

The error type that can be returned by the try_pow method. This type must implement std::error::Error for proper error handling.
Source§

fn try_pow(self, exponent: u32) -> Result<Self, Self::Error>

Attempts to compute self (the base) raised to the power of exponent. Read more
Source§

impl<RealType: RealScalar> Pow<u64> for PositiveRealScalar<RealType>

Source§

fn pow(self, exponent: u64) -> Self

Raises the number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, u64>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>

The error type that can be returned by the try_pow method. This type must implement std::error::Error for proper error handling.
Source§

fn try_pow(self, exponent: u64) -> Result<Self, Self::Error>

Attempts to compute self (the base) raised to the power of exponent. Read more
Source§

impl<RealType: RealScalar> Pow<u128> for PositiveRealScalar<RealType>

Source§

fn pow(self, exponent: u128) -> Self

Raises the number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, u128>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>

The error type that can be returned by the try_pow method. This type must implement std::error::Error for proper error handling.
Source§

fn try_pow(self, exponent: u128) -> Result<Self, Self::Error>

Attempts to compute self (the base) raised to the power of exponent. Read more
Source§

impl<RealType: RealScalar> Pow<usize> for PositiveRealScalar<RealType>

Source§

fn pow(self, exponent: usize) -> Self

Raises the number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, usize>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>

The error type that can be returned by the try_pow method. This type must implement std::error::Error for proper error handling.
Source§

fn try_pow(self, exponent: usize) -> Result<Self, Self::Error>

Attempts to compute self (the base) raised to the power of exponent. Read more
Source§

impl<RealType: RealScalar> ScalarCore for PositiveRealScalar<RealType>

Source§

type RawScalarType = <RealType as ScalarCore>::RawScalarType

The type of the inner value that will be extracted.
Source§

fn as_raw_scalar_ref(&self) -> &Self::RawScalarType

Returns a reference to the inner value.
Source§

fn into_raw_scalar(self) -> Self::RawScalarType

Consumes the scalar and returns its inner raw scalar value. Read more
Source§

fn eq_raw(&self, other: &Self::RawScalarType) -> bool

Compares this scalar with a value in its underlying raw representation. Read more
Source§

impl<RealType> Serialize for PositiveRealScalar<RealType>
where RealType: Serialize + RealScalar,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<RealType: PartialEq + RealScalar> StructuralPartialEq for PositiveRealScalar<RealType>

Source§

impl<RealType: RealScalar> TryNew for PositiveRealScalar<RealType>

Source§

fn try_new(value: RealType) -> Result<Self, Self::Error>

Attempts to create a PositiveRealScalar from a value.

§Errors
§Panics (Debug Mode Only)

In debug builds, panics if the input is not finite (NaN or infinity).

§Examples
use num_valid::scalars::{PositiveRealScalar, ErrorsPositiveRealScalar};
use try_create::TryNew;

// Positive value succeeds
assert!(PositiveRealScalar::try_new(1.0_f64).is_ok());

// Zero fails
assert!(matches!(
    PositiveRealScalar::try_new(0.0_f64),
    Err(ErrorsPositiveRealScalar::ZeroValue { .. })
));

// Negative fails
assert!(matches!(
    PositiveRealScalar::try_new(-1.0_f64),
    Err(ErrorsPositiveRealScalar::NegativeValue { value: v, .. }) if v == -1.0
));
Source§

type Error = ErrorsPositiveRealScalar<RealType>

The error type that can be returned by the try_new method.

Auto Trait Implementations§

§

impl<RealType> Freeze for PositiveRealScalar<RealType>
where RealType: Freeze,

§

impl<RealType> RefUnwindSafe for PositiveRealScalar<RealType>
where RealType: RefUnwindSafe,

§

impl<RealType> Send for PositiveRealScalar<RealType>

§

impl<RealType> Sync for PositiveRealScalar<RealType>

§

impl<RealType> Unpin for PositiveRealScalar<RealType>
where RealType: Unpin,

§

impl<RealType> UnsafeUnpin for PositiveRealScalar<RealType>
where RealType: UnsafeUnpin,

§

impl<RealType> UnwindSafe for PositiveRealScalar<RealType>
where RealType: UnwindSafe,

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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.