Skip to main content

Coerce

Trait Coerce 

Source
pub trait Coerce<R> {
    // Required method
    fn coerce(self) -> R;
}
Expand description

Infallible coercion from Self to type R.

Implement this trait for types that can always be converted to R. Identity and widening conversions should use this trait.

Works for both scalars and element-wise on slices:

  • i8::coerce() -> i32 (scalar widening)
  • &[i8]::coerce() -> Vec<i32> (element-wise)

§Example

impl Coerce<i32> for MyType {
    fn coerce(self) -> i32 { ... }
}

Required Methods§

Source

fn coerce(self) -> R

Convert self into R.

This conversion must not fail.

Implementations on Foreign Types§

Source§

impl Coerce<Rboolean> for bool

Source§

impl Coerce<f32> for f64

Source§

fn coerce(self) -> f32

Source§

impl Coerce<f32> for i32

Source§

fn coerce(self) -> f32

Source§

impl Coerce<f32> for u8

Source§

fn coerce(self) -> f32

Source§

impl Coerce<f64> for Option<f64>

Option<f64>f64 with NoneNA_real_.

Source§

fn coerce(self) -> f64

Source§

impl Coerce<f64> for bool

Source§

fn coerce(self) -> f64

Source§

impl Coerce<f64> for f64

Source§

fn coerce(self) -> f64

Source§

impl Coerce<i16> for i8

Source§

fn coerce(self) -> i16

Source§

impl Coerce<i16> for u8

Source§

fn coerce(self) -> i16

Source§

impl Coerce<i32> for Option<Rboolean>

Option<Rboolean>i32 with NoneNA_LOGICAL.

Source§

fn coerce(self) -> i32

Source§

impl Coerce<i32> for Option<bool>

Option<bool>i32 with NoneNA_LOGICAL.

Source§

fn coerce(self) -> i32

Source§

impl Coerce<i32> for Option<i32>

Option<i32>i32 with NoneNA_integer_.

Source§

fn coerce(self) -> i32

Source§

impl Coerce<i32> for bool

Source§

fn coerce(self) -> i32

Source§

impl Coerce<i32> for i32

Source§

fn coerce(self) -> i32

Source§

impl Coerce<i64> for i32

i32 -> i64: widening, always safe

Source§

fn coerce(self) -> i64

Source§

impl Coerce<i64> for u8

Source§

fn coerce(self) -> i64

Source§

impl Coerce<isize> for i32

i32 -> isize: always safe (isize is at least 32 bits)

Source§

fn coerce(self) -> isize

Source§

impl Coerce<isize> for u8

Source§

fn coerce(self) -> isize

Source§

impl Coerce<u8> for u8

Source§

fn coerce(self) -> u8

Source§

impl Coerce<u16> for u8

Source§

fn coerce(self) -> u16

Source§

impl Coerce<u32> for u8

Source§

fn coerce(self) -> u32

Source§

impl Coerce<u32> for u16

Source§

fn coerce(self) -> u32

Source§

impl Coerce<u64> for u8

Source§

fn coerce(self) -> u64

Source§

impl Coerce<usize> for u8

Source§

fn coerce(self) -> usize

Source§

impl<A, B, C, D, E, F, G, H, RA, RB, RC, RD, RE, RF, RG, RH> Coerce<(RA, RB, RC, RD, RE, RF, RG, RH)> for (A, B, C, D, E, F, G, H)
where A: Coerce<RA>, B: Coerce<RB>, C: Coerce<RC>, D: Coerce<RD>, E: Coerce<RE>, F: Coerce<RF>, G: Coerce<RG>, H: Coerce<RH>,

Source§

impl<A, B, C, D, E, F, G, RA, RB, RC, RD, RE, RF, RG> Coerce<(RA, RB, RC, RD, RE, RF, RG)> for (A, B, C, D, E, F, G)
where A: Coerce<RA>, B: Coerce<RB>, C: Coerce<RC>, D: Coerce<RD>, E: Coerce<RE>, F: Coerce<RF>, G: Coerce<RG>,

Source§

impl<A, B, C, D, E, F, RA, RB, RC, RD, RE, RF> Coerce<(RA, RB, RC, RD, RE, RF)> for (A, B, C, D, E, F)
where A: Coerce<RA>, B: Coerce<RB>, C: Coerce<RC>, D: Coerce<RD>, E: Coerce<RE>, F: Coerce<RF>,

Source§

impl<A, B, C, D, E, RA, RB, RC, RD, RE> Coerce<(RA, RB, RC, RD, RE)> for (A, B, C, D, E)
where A: Coerce<RA>, B: Coerce<RB>, C: Coerce<RC>, D: Coerce<RD>, E: Coerce<RE>,

Source§

impl<A, B, C, D, RA, RB, RC, RD> Coerce<(RA, RB, RC, RD)> for (A, B, C, D)
where A: Coerce<RA>, B: Coerce<RB>, C: Coerce<RC>, D: Coerce<RD>,

Source§

impl<A, B, C, RA, RB, RC> Coerce<(RA, RB, RC)> for (A, B, C)
where A: Coerce<RA>, B: Coerce<RB>, C: Coerce<RC>,

Source§

impl<A, B, RA, RB> Coerce<(RA, RB)> for (A, B)
where A: Coerce<RA>, B: Coerce<RB>,

Source§

impl<T: Copy + Coerce<R>, R> Coerce<Vec<R>> for &[T]

Coerce a slice element-wise to a Vec.

Source§

fn coerce(self) -> Vec<R>

Source§

impl<T: Coerce<R>, R> Coerce<Box<[R]>> for Box<[T]>

Infallible element-wise coercion for Box<[T]>Box<[R]>.

Source§

fn coerce(self) -> Box<[R]>

Source§

impl<T: Coerce<R>, R> Coerce<VecDeque<R>> for VecDeque<T>

Infallible element-wise coercion for VecDeque to VecDeque.

Source§

fn coerce(self) -> VecDeque<R>

Source§

impl<T: Coerce<R>, R> Coerce<Vec<R>> for Vec<T>

Coerce a Vec element-wise to a new Vec.

Source§

fn coerce(self) -> Vec<R>

Implementors§

Source§

impl Coerce<Rboolean> for Rboolean

Source§

impl Coerce<i32> for Rboolean

Source§

impl Coerce<Rcomplex> for Rcomplex

Source§

impl<T: WidensToF64> Coerce<f64> for T

Blanket impl: Any type that widens to f64 can be coerced to f64.

This replaces individual macro invocations with a single blanket impl. Covers: f32, i8, i16, i32, u8, u16, u32 (all types where T: Into<f64>).

Source§

impl<T: WidensToI32> Coerce<i32> for T

Blanket impl: Any type that widens to i32 can be coerced to i32.

This replaces individual macro invocations with a single blanket impl. Covers: i8, i16, u8, u16 (all types where T: Into<i32>).