Skip to main content

Rat

Struct Rat 

Source
pub struct Rat { /* private fields */ }
Expand description

A bounded rational num / den: canonical (den > 0, gcd(|num|, den) == 1) and bounded (|num|, den <= MAX_MAG), so structural equality is value equality and Eq/Hash derive safely. Ord is hand-written by cross-multiplication. The fields are private:

ⓘ
use the_q::Rat;
let _ = Rat { num: 1, den: 2 };
ⓘ
use the_q::Rat;
let mut r = Rat::one();
r.den = 0;

Implementations§

Source§

impl Rat

Source

pub fn numerator(&self) -> i64

The numerator of the canonical representation. Always coprime to Rat::denominator.

use the_q::Rat;

let r = Rat::new(-3, 6).unwrap();
assert_eq!(r.numerator(), -1);
assert_eq!(r.denominator(), 2);
Source

pub fn denominator(&self) -> i64

The denominator of the canonical representation. Always >= 1.

use the_q::Rat;

let r = Rat::new(3, 6).unwrap();
assert_eq!(r.denominator(), 2);
assert_eq!(Rat::one().denominator(), 1);
Source§

impl Rat

Source

pub fn zero() -> Rat

0.

use the_q::Rat;

let z = Rat::zero();
assert_eq!(z.numerator(), 0);
assert_eq!(z.denominator(), 1);
assert!(z.is_zero());
Source

pub fn one() -> Rat

1.

use the_q::Rat;

let o = Rat::one();
assert_eq!(o.numerator(), 1);
assert_eq!(o.denominator(), 1);
assert!(o.is_one());
Source

pub fn neg_one() -> Rat

-1.

use the_q::Rat;

let n = Rat::neg_one();
assert_eq!(n.numerator(), -1);
assert_eq!(n.denominator(), 1);
assert_eq!(n, Rat::one().neg());
Source

pub fn from_int(i: i64) -> Option<Rat>

The integer i as a rational.

None when |i| > MAX_MAG — in particular for i64::MIN, whose absolute value is not an i64 at all.

use the_q::{Rat, MAX_MAG};

let three = Rat::from_int(3).unwrap();
assert_eq!(three.numerator(), 3);
assert_eq!(three.denominator(), 1);

assert_eq!(Rat::from_int(MAX_MAG + 1), None);
assert_eq!(Rat::from_int(i64::MIN), None);
Source

pub fn new(num: i64, den: i64) -> Option<Rat>

The exact rational num / den, canonicalised. None when den == 0 or the reduced form exceeds the budget (Rat::new(i64::MAX, 1)); Rat::new_rounded rounds instead.

use the_q::Rat;

let half = Rat::new(2, 4).unwrap();
assert_eq!(half.numerator(), 1);
assert_eq!(half.denominator(), 2);

assert_eq!(Rat::new(1, 0), None);
assert_eq!(Rat::new(i64::MAX, 1), None);
Source

pub fn new_rounded(num: i64, den: i64, dir: Dir) -> Option<Rat>

num / den, rounded to the budget if it does not fit; None iff den == 0. The sign is normalised onto the numerator before rounding.

use the_q::{Dir, Rat};

assert_eq!(Rat::new_rounded(6, 4, Dir::Nearest), Rat::new(3, 2));
// Sign normalisation: a negative denominator folds onto the numerator.
assert_eq!(Rat::new_rounded(-3, -4, Dir::Down), Rat::new(3, 4));
assert_eq!(Rat::new_rounded(1, 0, Dir::Nearest), None);
Source

pub fn from_decimal(mantissa: i64, dec_places: u8) -> Option<Rat>

The exact decimal mantissa · 10^-dec_places; (85, 2) is 0.85. None when dec_places > 18 or |mantissa| > MAX_MAG.

use the_q::{Rat, MAX_DEC_PLACES};

assert_eq!(Rat::from_decimal(85, 2), Rat::new(17, 20));
assert_eq!(Rat::from_decimal(1, MAX_DEC_PLACES + 1), None);
Source§

impl Rat

Source

pub fn add_dir(a: Rat, b: Rat, dir: Dir) -> Rat

a + b, rounded in direction dir.

use the_q::{Dir, Rat};

let a = Rat::new(1, 3).unwrap();
let b = Rat::new(1, 6).unwrap();
assert_eq!(Rat::add_dir(a, b, Dir::Down), Rat::new(1, 2).unwrap());

// `Down` and `Up` bracket the exact value; they agree on the exact path.
let a = Rat::new(1, 3_037_000_493).unwrap();
let b = Rat::new(1, 3_037_000_499).unwrap();
let lo = Rat::add_dir(a, b, Dir::Down);
let hi = Rat::add_dir(a, b, Dir::Up);
assert!(Rat::lt(lo, hi));
Source

pub fn sub_dir(a: Rat, b: Rat, dir: Dir) -> Rat

a - b, rounded in direction dir.

use the_q::{Dir, Rat};

let a = Rat::new(3, 4).unwrap();
let b = Rat::new(1, 4).unwrap();
assert_eq!(Rat::sub_dir(a, b, Dir::Up), Rat::new(1, 2).unwrap());

// `Down` and `Up` bracket the exact value.
let lo = Rat::sub_dir(a, b, Dir::Down);
let hi = Rat::sub_dir(a, b, Dir::Up);
assert!(Rat::le(lo, hi));
Source

pub fn mul_dir(a: Rat, b: Rat, dir: Dir) -> Rat

a * b, rounded in direction dir.

use the_q::{Dir, Rat};

let a = Rat::new(2, 3).unwrap();
let b = Rat::new(3, 4).unwrap();
assert_eq!(Rat::mul_dir(a, b, Dir::Down), Rat::new(1, 2).unwrap());

// `Down` and `Up` bracket the exact value.
let lo = Rat::mul_dir(a, b, Dir::Down);
let hi = Rat::mul_dir(a, b, Dir::Up);
assert!(Rat::le(lo, hi));
Source

pub fn div_dir(a: Rat, b: Rat, dir: Dir) -> Rat

a / b in direction dir. b != 0 is a precondition; an unverified caller with a zero divisor panics here. Use Rat::checked_div or crate::Q::div.

use the_q::{Dir, Rat};

let a = Rat::new(1, 2).unwrap();
let b = Rat::new(1, 3).unwrap();
assert_eq!(Rat::div_dir(a, b, Dir::Down), Rat::new(3, 2).unwrap());
ⓘ
use the_q::{Dir, Rat};

let a = Rat::new(1, 2).unwrap();
let _ = Rat::div_dir(a, Rat::zero(), Dir::Down);
Source

pub fn add(a: Rat, b: Rat) -> Rat

a + b, round to nearest (ties to even).

The error is a half grid step and not a whole one, thus this operation achieves B = 62. That is one bit better than the B = 61 of the directed modes. See round::lemma_r3_error_nearest.

use the_q::Rat;

let a = Rat::new(1, 3).unwrap();
let b = Rat::new(1, 6).unwrap();
assert_eq!(Rat::add(a, b), Rat::new(1, 2).unwrap());
assert_eq!(Rat::add(a, Rat::zero()), a);
Source

pub fn sub(a: Rat, b: Rat) -> Rat

a - b, round to nearest (ties to even). Achieves B = 62, as add does.

use the_q::Rat;

let a = Rat::new(3, 4).unwrap();
let b = Rat::new(1, 4).unwrap();
assert_eq!(Rat::sub(a, b), Rat::new(1, 2).unwrap());
assert_eq!(Rat::sub(a, a), Rat::zero());
Source

pub fn mul(a: Rat, b: Rat) -> Rat

a * b, round to nearest (ties to even). Achieves B = 62, as add does.

use the_q::Rat;

let a = Rat::new(2, 3).unwrap();
let b = Rat::new(3, 4).unwrap();
assert_eq!(Rat::mul(a, b), Rat::new(1, 2).unwrap());
assert_eq!(Rat::mul(a, Rat::one()), a);
Source

pub fn div(a: Rat, b: Rat) -> Rat

a / b, round to nearest (ties to even). Requires !b.is_zero(). Achieves B = 62, as add does.

use the_q::Rat;

let a = Rat::new(1, 2).unwrap();
let b = Rat::new(1, 3).unwrap();
assert_eq!(Rat::div(a, b), Rat::new(3, 2).unwrap());
ⓘ
use the_q::Rat;

let a = Rat::new(1, 2).unwrap();
let _ = Rat::div(a, Rat::zero());
Source

pub fn checked_add(a: Rat, b: Rat) -> Option<Rat>

a + b, or None if the exact sum is too large in magnitude to be represented at all (|a + b| > MAX_MAG).

use the_q::{Rat, MAX_MAG};

let a = Rat::new(1, 3).unwrap();
let b = Rat::new(1, 6).unwrap();
assert_eq!(Rat::checked_add(a, b), Some(Rat::new(1, 2).unwrap()));

// `MAX_MAG + 1` is past the budget, not merely rounded.
let max = Rat::from_int(MAX_MAG).unwrap();
assert_eq!(Rat::checked_add(max, Rat::one()), None);
Source

pub fn checked_mul(a: Rat, b: Rat) -> Option<Rat>

a * b, or None if the exact product is too large in magnitude.

use the_q::{Rat, MAX_MAG};

let a = Rat::new(2, 3).unwrap();
let b = Rat::new(3, 4).unwrap();
assert_eq!(Rat::checked_mul(a, b), Some(Rat::new(1, 2).unwrap()));

let max = Rat::from_int(MAX_MAG).unwrap();
let two = Rat::from_int(2).unwrap();
assert_eq!(Rat::checked_mul(max, two), None);
Source

pub fn checked_sub(a: Rat, b: Rat) -> Option<Rat>

a - b, or None if the exact difference is too large in magnitude.

use the_q::{Rat, MAX_MAG};

let a = Rat::new(3, 4).unwrap();
let b = Rat::new(1, 4).unwrap();
assert_eq!(Rat::checked_sub(a, b), Some(Rat::new(1, 2).unwrap()));

let neg_max = Rat::from_int(-MAX_MAG).unwrap();
assert_eq!(Rat::checked_sub(neg_max, Rat::one()), None);
Source

pub fn checked_sub_dir(a: Rat, b: Rat, dir: Dir) -> Option<Rat>

a - b, rounded in dir, or None if the exact difference is too large in magnitude. Unlike Rat::checked_sub, this preserves the requested rounding direction when the result is not exact.

use the_q::{Dir, Rat, MAX_MAG};

let a = Rat::new(3, 4).unwrap();
let b = Rat::new(1, 4).unwrap();
assert_eq!(Rat::checked_sub_dir(a, b, Dir::Down), Some(Rat::new(1, 2).unwrap()));

let neg_max = Rat::from_int(-MAX_MAG).unwrap();
assert_eq!(Rat::checked_sub_dir(neg_max, Rat::one(), Dir::Down), None);
Source

pub fn checked_div(a: Rat, b: Rat) -> Option<Rat>

a / b, or None on a zero divisor or a quotient past the budget.

use the_q::{Rat, MAX_MAG};

let a = Rat::new(1, 2).unwrap();
let b = Rat::new(1, 3).unwrap();
assert_eq!(Rat::checked_div(a, b), Some(Rat::new(3, 2).unwrap()));

assert_eq!(Rat::checked_div(a, Rat::zero()), None);

let max = Rat::from_int(MAX_MAG).unwrap();
let half = Rat::new(1, 2).unwrap();
assert_eq!(Rat::checked_div(max, half), None);
Source

pub fn neg(self) -> Rat

-a. Always exact: the budget is symmetric in sign.

use the_q::Rat;

let a = Rat::new(3, 4).unwrap();
assert_eq!(a.neg(), Rat::new(-3, 4).unwrap());
assert_eq!(a.neg().neg(), a);
Source

pub fn abs(self) -> Rat

|a|. Always exact.

use the_q::Rat;

let a = Rat::new(-3, 4).unwrap();
assert_eq!(a.abs(), Rat::new(3, 4).unwrap());
assert_eq!(a.abs().abs(), a.abs());
Source

pub fn recip(self) -> Rat

1 / a, exact (a swap of a canonical pair). Zero is a precondition and panics for an unverified caller; crate::Q::recip gives PosInf.

use the_q::Rat;

let a = Rat::new(-2, 3).unwrap();
assert_eq!(a.recip(), Rat::new(-3, 2).unwrap());
assert_eq!(Rat::mul(a, a.recip()), Rat::one());
ⓘ
use the_q::Rat;

let _ = Rat::zero().recip();
Source

pub fn pow_u32(self, e: u32) -> Rat

a^e by repeated multiplication, as a left fold. This module has no rational-exponent power.

use the_q::Rat;

let a = Rat::new(2, 3).unwrap();
assert_eq!(a.pow_u32(3), Rat::new(8, 27).unwrap());
assert_eq!(a.pow_u32(0), Rat::one());
Source§

impl Rat

Source

pub fn compare(a: Rat, b: Rat) -> i32

Three-way comparison, -1/0/1, exact by i128 cross-multiplication.

use the_q::Rat;

let a = Rat::new(1, 3).unwrap();
let b = Rat::new(1, 2).unwrap();
assert_eq!(Rat::compare(a, b), -1);
assert_eq!(Rat::compare(b, a), 1);
assert_eq!(Rat::compare(a, a), 0);
Source

pub fn eq_q(a: Rat, b: Rat) -> bool

a == b. Because Rat is canonical this is also structural equality.

use the_q::Rat;

let a = Rat::new(1, 2).unwrap();
let b = Rat::new(2, 4).unwrap();
assert!(Rat::eq_q(a, b));
assert!(!Rat::eq_q(a, Rat::one()));
Source

pub fn lt(a: Rat, b: Rat) -> bool

a < b.

use the_q::Rat;

let a = Rat::new(1, 3).unwrap();
let b = Rat::new(1, 2).unwrap();
assert!(Rat::lt(a, b));
assert!(!Rat::lt(a, a));
Source

pub fn le(a: Rat, b: Rat) -> bool

a <= b.

use the_q::Rat;

let a = Rat::new(1, 3).unwrap();
let b = Rat::new(1, 2).unwrap();
assert!(Rat::le(a, b));
assert!(Rat::le(a, a));
assert!(!Rat::le(b, a));
Source

pub fn gt(a: Rat, b: Rat) -> bool

a > b.

use the_q::Rat;

let a = Rat::new(1, 2).unwrap();
let b = Rat::new(1, 3).unwrap();
assert!(Rat::gt(a, b));
assert!(!Rat::gt(a, a));
Source

pub fn ge(a: Rat, b: Rat) -> bool

a >= b.

use the_q::Rat;

let a = Rat::new(1, 2).unwrap();
let b = Rat::new(1, 3).unwrap();
assert!(Rat::ge(a, b));
assert!(Rat::ge(a, a));
assert!(!Rat::ge(b, a));
Source

pub fn is_zero(&self) -> bool

a == 0.

use the_q::Rat;

assert!(Rat::zero().is_zero());
assert!(!Rat::one().is_zero());
Source

pub fn is_one(&self) -> bool

a == 1.

use the_q::Rat;

assert!(Rat::one().is_one());
assert!(!Rat::zero().is_one());
Source

pub fn signum(&self) -> i32

-1, 0 or 1 according to the sign.

use the_q::Rat;

assert_eq!(Rat::new(-3, 4).unwrap().signum(), -1);
assert_eq!(Rat::zero().signum(), 0);
assert_eq!(Rat::new(3, 4).unwrap().signum(), 1);
Source

pub fn in_unit_interval(&self) -> bool

0 <= a <= 1.

The consuming engine checks this constantly on beliefs, disbeliefs and uncertainties, so it is a first-class predicate rather than two comparisons.

use the_q::Rat;

assert!(Rat::new(1, 2).unwrap().in_unit_interval());
assert!(Rat::one().in_unit_interval());
assert!(!Rat::new(-1, 2).unwrap().in_unit_interval());
assert!(!Rat::new(3, 2).unwrap().in_unit_interval());
Source

pub fn min(a: Rat, b: Rat) -> Rat

The smaller of a and b. Exact.

use the_q::Rat;

let a = Rat::new(1, 3).unwrap();
let b = Rat::new(1, 2).unwrap();
assert_eq!(Rat::min(a, b), a);
assert_eq!(Rat::min(b, a), a);
Source

pub fn max(a: Rat, b: Rat) -> Rat

The larger of a and b. Exact.

use the_q::Rat;

let a = Rat::new(1, 3).unwrap();
let b = Rat::new(1, 2).unwrap();
assert_eq!(Rat::max(a, b), b);
assert_eq!(Rat::max(b, a), b);
Source

pub fn clamp(a: Rat, lo: Rat, hi: Rat) -> Rat

a clamped into [lo, hi]. Exact. Requires lo <= hi.

use the_q::Rat;

let lo = Rat::zero();
let hi = Rat::one();
let mid = Rat::new(1, 2).unwrap();
assert_eq!(Rat::clamp(mid, lo, hi), mid);
assert_eq!(Rat::clamp(Rat::new(-1, 2).unwrap(), lo, hi), lo);
assert_eq!(Rat::clamp(Rat::new(3, 2).unwrap(), lo, hi), hi);

Trait Implementations§

Source§

impl Add for Rat

Source§

type Output = Rat

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Rat) -> Rat

Performs the + operation. Read more
Source§

impl Clone for Rat

Source§

fn clone(&self) -> Rat

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 Copy for Rat

Source§

impl Debug for Rat

Source§

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

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

impl<'de> Deserialize<'de> for Rat

Available on crate feature serde only.
Source§

fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Rat, D::Error>

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

impl Display for Rat

Source§

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

"num/den", always in canonical form. The string is thus a faithful and unambiguous rendering of the value.

Source§

impl Eq for Rat

Source§

impl Hash for Rat

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Mul for Rat

Source§

type Output = Rat

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Rat) -> Rat

Performs the * operation. Read more
Source§

impl Neg for Rat

Source§

type Output = Rat

The resulting type after applying the - operator.
Source§

fn neg(self) -> Rat

Performs the unary - operation. Read more
Source§

impl Ord for Rat

Source§

fn cmp(&self, other: &Rat) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Rat

Source§

fn eq(&self, other: &Rat) -> bool

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

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Rat

Source§

fn partial_cmp(&self, other: &Rat) -> 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 Serialize for Rat

Available on crate feature serde only.

The (num, den) pair, exact; decoding re-canonicalises through Rat::new and rejects a malformed payload.

Source§

fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>

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

impl StructuralPartialEq for Rat

Source§

impl Sub for Rat

Source§

type Output = Rat

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Rat) -> Rat

Performs the - operation. Read more

Auto Trait Implementations§

§

impl Freeze for Rat

§

impl RefUnwindSafe for Rat

§

impl Send for Rat

§

impl Sync for Rat

§

impl Unpin for Rat

§

impl UnsafeUnpin for Rat

§

impl UnwindSafe for Rat

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.