Into

A value-to-value conversion that consumes the input value.Note: This trait must not fail. If the conversion can fail, use TryInto. # Generic ImplementationsInto is reflexive, which means that Into<T, T> is implemented # ExamplesConverting from RGB components to a packed color value:

[derive(Copy, Drop, PartialEq)]
struct Color {
    // Packed as 0x00RRGGBB
    value: u32,
}

impl RGBIntoColor of Into<(u8, u8, u8), Color> {
    fn into(self: (u8, u8, u8)) -> Color {
        let (r, g, b) = self;
        let value = (r.into() * 0x10000_u32) +
                   (g.into() * 0x100_u32) +
                   b.into();
        Color { value }
    }
}

// Convert RGB(255, 128, 0) to 0x00FF8000
let orange: Color = (255_u8, 128_u8, 0_u8).into();
assert!(orange == Color { value: 0x00FF8000_u32 });

Fully qualified path: core::traits::Into

pub trait Into<T, S>

Trait functions

into

Converts the input type T into the output type S. # Examples

let a: u8 = 1;
let b: u16 = a.into();

Fully qualified path: core::traits::Into::into

fn into(self: T) -> S