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.
Pair: TryCoerce for fallible (narrowing) coercions. Strict alternative
on the inbound side: crate::from_r::TryFromSexp.
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§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
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)
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)
fn coerce(self) -> (RA, RB, RC, RD, RE, RF, RG, 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)
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)
fn coerce(self) -> (RA, RB, RC, RD, RE, RF, 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)
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)
fn coerce(self) -> (RA, RB, RC, RD, RE, 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)
impl<A, B, C, D, E, RA, RB, RC, RD, RE> Coerce<(RA, RB, RC, RD, RE)> for (A, B, C, D, E)
fn coerce(self) -> (RA, RB, RC, RD, RE)
Source§impl<A, B, C, D, RA, RB, RC, RD> Coerce<(RA, RB, RC, RD)> for (A, B, C, D)
impl<A, B, C, D, RA, RB, RC, RD> Coerce<(RA, RB, RC, RD)> for (A, B, C, D)
fn coerce(self) -> (RA, RB, RC, RD)
Source§impl<A, B, C, RA, RB, RC> Coerce<(RA, RB, RC)> for (A, B, C)
impl<A, B, C, RA, RB, RC> Coerce<(RA, RB, RC)> for (A, B, C)
fn coerce(self) -> (RA, RB, RC)
Source§impl<T: Coerce<R>, R> Coerce<Box<[R]>> for Box<[T]>
Infallible element-wise coercion for Box<[T]> → Box<[R]>.
impl<T: Coerce<R>, R> Coerce<Box<[R]>> for Box<[T]>
Infallible element-wise coercion for Box<[T]> → Box<[R]>.
Source§impl<T: Coerce<R>, R> Coerce<VecDeque<R>> for VecDeque<T>
Infallible element-wise coercion for VecDeque to VecDeque.
impl<T: Coerce<R>, R> Coerce<VecDeque<R>> for VecDeque<T>
Infallible element-wise coercion for VecDeque to VecDeque.
Implementors§
impl Coerce<Rboolean> for Rboolean
impl Coerce<Rcomplex> for Rcomplex
impl Coerce<i32> for Rboolean
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>).
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>).