Trait wasmtime_wiggle::bitflags::_core::prelude::rust_2018::Into1.0.0[][src]

pub trait Into<T> {
    fn into(self) -> T;
}
Expand description

A value-to-value conversion that consumes the input value. The opposite of From.

One should avoid implementing Into and implement From instead. Implementing From automatically provides one with an implementation of Into thanks to the blanket implementation in the standard library.

Prefer using Into over From when specifying trait bounds on a generic function to ensure that types that only implement Into can be used as well.

Note: This trait must not fail. If the conversion can fail, use TryInto.

Generic Implementations

  • From<T> for U implies Into<U> for T
  • Into is reflexive, which means that Into<T> for T is implemented

Implementing Into for conversions to external types in old versions of Rust

Prior to Rust 1.41, if the destination type was not part of the current crate then you couldn’t implement From directly. For example, take this code:

struct Wrapper<T>(Vec<T>);
impl<T> From<Wrapper<T>> for Vec<T> {
    fn from(w: Wrapper<T>) -> Vec<T> {
        w.0
    }
}

This will fail to compile in older versions of the language because Rust’s orphaning rules used to be a little bit more strict. To bypass this, you could implement Into directly:

struct Wrapper<T>(Vec<T>);
impl<T> Into<Vec<T>> for Wrapper<T> {
    fn into(self) -> Vec<T> {
        self.0
    }
}

It is important to understand that Into does not provide a From implementation (as From does with Into). Therefore, you should always try to implement From and then fall back to Into if From can’t be implemented.

Examples

String implements Into<Vec<u8>>:

In order to express that we want a generic function to take all arguments that can be converted to a specified type T, we can use a trait bound of Into<T>. For example: The function is_hello takes all arguments that can be converted into a Vec<u8>.

fn is_hello<T: Into<Vec<u8>>>(s: T) {
   let bytes = b"hello".to_vec();
   assert_eq!(bytes, s.into());
}

let s = "hello".to_string();
is_hello(s);

Required methods

fn into(self) -> T[src]

Performs the conversion.

Implementations on Foreign Types

impl Into<ExitStatus> for ExitStatusError[src]

pub fn into(self) -> ExitStatus[src]

impl Into<u8> for Register

pub fn into(self) -> u8

impl Into<i64> for Offset32

pub fn into(self) -> i64

impl Into<u64> for Uimm64

pub fn into(self) -> u64

impl Into<u32> for Uimm32

pub fn into(self) -> u32

impl Into<Vec<VerifierError, Global>> for VerifierErrors

pub fn into(self) -> Vec<VerifierError, Global>

impl Into<i64> for Uimm32

pub fn into(self) -> i64

impl Into<Result<(), VerifierErrors>> for VerifierErrors

pub fn into(self) -> Result<(), VerifierErrors>

impl Into<i64> for Imm64

pub fn into(self) -> i64

impl Into<i32> for Offset32

pub fn into(self) -> i32

impl<T> Into<Option<T>> for PackedOption<T> where
    T: ReservedValue, 

pub fn into(self) -> Option<T>

impl Into<u8> for OpcodePrefix

pub fn into(self) -> u8

impl Into<u64> for Pointer

pub fn into(self) -> u64

impl<'input, Endian> Into<&'input [u8]> for EndianSlice<'input, Endian> where
    Endian: Endianity, 

pub fn into(self) -> &'input [u8]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]

impl Into<u32> for InstIx

pub fn into(self) -> u32

impl Into<u32> for BlockIx

pub fn into(self) -> u32

impl<A, B> Into<Option<Either<A, B>>> for EitherOrBoth<A, B>[src]

pub fn into(self) -> Option<Either<A, B>>[src]

impl<L, R> Into<Result<R, L>> for Either<L, R>[src]

Convert from Either to Result with Right => Ok and Left => Err.

pub fn into(self) -> Result<R, L>[src]

impl Into<[u128; 4]> for vec512_storage

pub fn into(self) -> [u128; 4]

impl Into<[u128; 2]> for vec256_storage

pub fn into(self) -> [u128; 2]

impl Into<[u32; 16]> for vec512_storage

pub fn into(self) -> [u32; 16]

impl Into<[u32; 4]> for vec128_storage

pub fn into(self) -> [u32; 4]

impl<'a> Into<&'a [u32; 4]> for &'a vec128_storage

pub fn into(self) -> &'a [u32; 4]

impl Into<[u32; 8]> for vec256_storage

pub fn into(self) -> [u32; 8]

impl Into<[u128; 1]> for vec128_storage

pub fn into(self) -> [u128; 1]

impl Into<[u64; 2]> for vec128_storage

pub fn into(self) -> [u64; 2]

impl Into<[u64; 4]> for vec256_storage

pub fn into(self) -> [u64; 4]

impl Into<vec256_storage> for [u64; 4]

pub fn into(self) -> vec256_storage

impl Into<vec128_storage> for [u32; 4]

pub fn into(self) -> vec128_storage

impl Into<[u64; 8]> for vec512_storage

pub fn into(self) -> [u64; 8]

impl Into<Vec<BacktraceFrame, Global>> for Backtrace[src]

Implementors

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]