Skip to main content

Positive

Struct Positive 

Source
pub struct Positive<T> { /* private fields */ }
Expand description

A numeric value guaranteed to be strictly positive (> 0).

Useful for operations that require nonzero values, such as Field::reciprocal.

Implementations§

Source§

impl Positive<f32>

Source

pub fn try_new(v: f32) -> Option<Positive<f32>>

Attempt to construct a Positive from a value. Returns None if the value is not strictly positive.

Source

pub fn get(self) -> f32

Get the inner value.

Source

pub fn reciprocal(self) -> Positive<f32>

Safe reciprocal: always valid for positive values.

Source§

impl Positive<f64>

Source

pub fn try_new(v: f64) -> Option<Positive<f64>>

Attempt to construct a Positive from a value. Returns None if the value is not strictly positive.

Source

pub fn get(self) -> f64

Get the inner value.

Source

pub fn reciprocal(self) -> Positive<f64>

Safe reciprocal: always valid for positive values.

Source§

impl Positive<i8>

Source

pub fn try_new(v: i8) -> Option<Positive<i8>>

Attempt to construct a Positive from a value. Returns None if the value is zero or negative.

Source

pub fn get(self) -> i8

Get the inner value.

Source§

impl Positive<i16>

Source

pub fn try_new(v: i16) -> Option<Positive<i16>>

Attempt to construct a Positive from a value. Returns None if the value is zero or negative.

Source

pub fn get(self) -> i16

Get the inner value.

Source§

impl Positive<i32>

Source

pub fn try_new(v: i32) -> Option<Positive<i32>>

Attempt to construct a Positive from a value. Returns None if the value is zero or negative.

Source

pub fn get(self) -> i32

Get the inner value.

Source§

impl Positive<i64>

Source

pub fn try_new(v: i64) -> Option<Positive<i64>>

Attempt to construct a Positive from a value. Returns None if the value is zero or negative.

Source

pub fn get(self) -> i64

Get the inner value.

Source§

impl Positive<i128>

Source

pub fn try_new(v: i128) -> Option<Positive<i128>>

Attempt to construct a Positive from a value. Returns None if the value is zero or negative.

Source

pub fn get(self) -> i128

Get the inner value.

Source§

impl Positive<u8>

Source

pub fn try_new(v: u8) -> Option<Positive<u8>>

Attempt to construct a Positive from a value. Returns None if the value is zero or negative.

Source

pub fn get(self) -> u8

Get the inner value.

Source§

impl Positive<u16>

Source

pub fn try_new(v: u16) -> Option<Positive<u16>>

Attempt to construct a Positive from a value. Returns None if the value is zero or negative.

Source

pub fn get(self) -> u16

Get the inner value.

Source§

impl Positive<u32>

Source

pub fn try_new(v: u32) -> Option<Positive<u32>>

Attempt to construct a Positive from a value. Returns None if the value is zero or negative.

Source

pub fn get(self) -> u32

Get the inner value.

Source§

impl Positive<u64>

Source

pub fn try_new(v: u64) -> Option<Positive<u64>>

Attempt to construct a Positive from a value. Returns None if the value is zero or negative.

Source

pub fn get(self) -> u64

Get the inner value.

Source§

impl Positive<u128>

Source

pub fn try_new(v: u128) -> Option<Positive<u128>>

Attempt to construct a Positive from a value. Returns None if the value is zero or negative.

Source

pub fn get(self) -> u128

Get the inner value.

Source§

impl Positive<u8>

Source

pub fn from_nonzero(v: u8) -> Option<Positive<u8>>

Construct from a nonzero unsigned value. Returns None if zero.

Source§

impl Positive<u16>

Source

pub fn from_nonzero(v: u16) -> Option<Positive<u16>>

Construct from a nonzero unsigned value. Returns None if zero.

Source§

impl Positive<u32>

Source

pub fn from_nonzero(v: u32) -> Option<Positive<u32>>

Construct from a nonzero unsigned value. Returns None if zero.

Source§

impl Positive<u64>

Source

pub fn from_nonzero(v: u64) -> Option<Positive<u64>>

Construct from a nonzero unsigned value. Returns None if zero.

Source§

impl Positive<u128>

Source

pub fn from_nonzero(v: u128) -> Option<Positive<u128>>

Construct from a nonzero unsigned value. Returns None if zero.

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> Positive<T>

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<T> Copy for Positive<T>
where T: Copy,

Source§

impl<T> Debug for Positive<T>
where T: Debug,

Source§

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

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

impl<T> PartialEq for Positive<T>
where T: PartialEq,

Source§

fn eq(&self, other: &Positive<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialOrd for Positive<T>
where T: PartialOrd,

Source§

fn partial_cmp(&self, other: &Positive<T>) -> 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<T> StructuralPartialEq for Positive<T>
where T: PartialEq,

Auto Trait Implementations§

§

impl<T> Freeze for Positive<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Positive<T>
where T: RefUnwindSafe,

§

impl<T> Send for Positive<T>
where T: Send,

§

impl<T> Sync for Positive<T>
where T: Sync,

§

impl<T> Unpin for Positive<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Positive<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Positive<T>
where T: 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> 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> 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> 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

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.