TryInto.
Signature
Generic Implementations
Intois reflexive, which means thatIntois implemented
TryInto.
pub trait Into
Into is reflexive, which means that Into is implemented#[derive(Copy, Drop, PartialEq)]
struct Color {
// Packed as 0x00RRGGBB
value: u32,
}
impl RGBIntoColor of Into {
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 });
fn into(self: T) -> S
let a: u8 = 1;
let b: u16 = a.into();
Was this page helpful?