add examle

This commit is contained in:
qwjyh 2025-01-29 01:50:34 +09:00
parent fc257be1a4
commit 72fe5a657c

View file

@ -48,7 +48,7 @@ impl TryFrom<u32> for MyType2Val {
match value { match value {
0x1 => Ok(MyType2Val::A), 0x1 => Ok(MyType2Val::A),
0x2 => Ok(MyType2Val::B), 0x2 => Ok(MyType2Val::B),
_ => panic!() _ => panic!(),
} }
} }
} }
@ -68,4 +68,8 @@ fn main() {
let x = MyType1 {}; let x = MyType1 {};
println!("{}", x.converted()); println!("{}", x.converted());
let y = MyType2Val::A;
let _y = <MyType2Val as TryInto<u32>>::try_into(y).unwrap();
let _y = <MyType2Val as Into<u32>>::into(y);
} }