#[test] fn test_try_into() { letmut i = MixedInts::SmallInt(42);
assert_eq!(42i32, i.try_into().unwrap());
assert_eq!(&42i32, <_ as TryInto<&i32>>::try_into(&i).unwrap());
assert_eq!(
&mut42i32,
<_ as TryInto<&mut i32>>::try_into(&mut i).unwrap()
);
assert_eq!(
i64::try_from(i).unwrap_err().to_string(), "Only NamedBigInt, UnsignedWithIgnoredField, NamedUnsignedWithIgnoredField can be converted to i64"
);
assert_eq!(i64::try_from(i).unwrap_err().input, MixedInts::SmallInt(42));
assert_eq!(
<(i32, i32)>::try_from(i).unwrap_err().to_string(), "Only TwoSmallInts can be converted to (i32, i32)"
);
assert_eq!(
<(i64, i64)>::try_from(i).unwrap_err().to_string(), "Only NamedBigInts can be converted to (i64, i64)"
);
assert_eq!(
u32::try_from(i).unwrap_err().to_string(), "Only Unsigned, NamedUnsigned can be converted to u32"
);
assert_eq!(
<()>::try_from(i).unwrap_err().to_string(), "Only Unit can be converted to ()"
);
letmut i = MixedInts::NamedBigInt { int: 42 };
assert_eq!(
i32::try_from(i).unwrap_err().to_string(), "Only SmallInt can be converted to i32"
);
assert_eq!(42i64, i.try_into().unwrap());
assert_eq!(&42i64, <_ as TryInto<&i64>>::try_into(&i).unwrap());
assert_eq!(
&mut42i64,
<_ as TryInto<&mut i64>>::try_into(&mut i).unwrap()
);
assert_eq!(
<(i32, i32)>::try_from(i).unwrap_err().to_string(), "Only TwoSmallInts can be converted to (i32, i32)"
);
assert_eq!(
<(i64, i64)>::try_from(i).unwrap_err().to_string(), "Only NamedBigInts can be converted to (i64, i64)"
);
assert_eq!(
u32::try_from(i).unwrap_err().to_string(), "Only Unsigned, NamedUnsigned can be converted to u32"
);
assert_eq!(
<()>::try_from(i).unwrap_err().to_string(), "Only Unit can be converted to ()"
);
letmut i = MixedInts::TwoSmallInts(42, 64);
assert_eq!(
i32::try_from(i).unwrap_err().to_string(), "Only SmallInt can be converted to i32"
);
assert_eq!(
i64::try_from(i).unwrap_err().to_string(), "Only NamedBigInt, UnsignedWithIgnoredField, NamedUnsignedWithIgnoredField can be converted to i64"
);
assert_eq!((42i32, 64i32), i.try_into().unwrap());
assert_eq!((&42i32, &64i32), (&i).try_into().unwrap());
assert_eq!((&mut42i32, &mut64i32), (&an style='color:red'>mut i).try_into().unwrap());
assert_eq!(
<(i64, i64)>::try_from(i).unwrap_err().to_string(), "Only NamedBigInts can be converted to (i64, i64)"
);
assert_eq!(
u32::try_from(i).unwrap_err().to_string(), "Only Unsigned, NamedUnsigned can be converted to u32"
);
assert_eq!(
<()>::try_from(i).unwrap_err().to_string(), "Only Unit can be converted to ()"
);
letmut i = MixedInts::NamedBigInts { x: 42, y: 64 };
assert_eq!(
i32::try_from(i).unwrap_err().to_string(), "Only SmallInt can be converted to i32"
);
assert_eq!(
i64::try_from(i).unwrap_err().to_string(), "Only NamedBigInt, UnsignedWithIgnoredField, NamedUnsignedWithIgnoredField can be converted to i64"
);
assert_eq!(
<(i32, i32)>::try_from(i).unwrap_err().to_string(), "Only TwoSmallInts can be converted to (i32, i32)"
);
assert_eq!((42i64, 64i64), i.try_into().unwrap());
assert_eq!((&42i64, &64i64), (&i).try_into().unwrap());
assert_eq!((&mut42i64, &mut64i64), (&an style='color:red'>mut i).try_into().unwrap());
assert_eq!(
u32::try_from(i).unwrap_err().to_string(), "Only Unsigned, NamedUnsigned can be converted to u32"
);
assert_eq!(
<()>::try_from(i).unwrap_err().to_string(), "Only Unit can be converted to ()"
);
letmut i = MixedInts::Unsigned(42);
assert_eq!(
i32::try_from(i).unwrap_err().to_string(), "Only SmallInt can be converted to i32"
);
assert_eq!(
i64::try_from(i).unwrap_err().to_string(), "Only NamedBigInt, UnsignedWithIgnoredField, NamedUnsignedWithIgnoredField can be converted to i64"
);
assert_eq!(
<(i32, i32)>::try_from(i).unwrap_err().to_string(), "Only TwoSmallInts can be converted to (i32, i32)"
);
assert_eq!(
<(i64, i64)>::try_from(i).unwrap_err().to_string(), "Only NamedBigInts can be converted to (i64, i64)"
);
assert_eq!(42u32, i.try_into().unwrap());
assert_eq!(&42u32, <_ as TryInto<&u32>>::try_into(&i).unwrap());
assert_eq!(
&mut42u32,
<_ as TryInto<&mut u32>>::try_into(&mut i).unwrap()
);
assert_eq!(
<()>::try_from(i).unwrap_err().to_string(), "Only Unit can be converted to ()"
);
letmut i = MixedInts::NamedUnsigned { x: 42 };
assert_eq!(
i32::try_from(i).unwrap_err().to_string(), "Only SmallInt can be converted to i32"
);
assert_eq!(
i64::try_from(i).unwrap_err().to_string(), "Only NamedBigInt, UnsignedWithIgnoredField, NamedUnsignedWithIgnoredField can be converted to i64"
);
assert_eq!(
i64::try_from(i).unwrap_err().to_string(), "Only NamedBigInt, UnsignedWithIgnoredField, NamedUnsignedWithIgnoredField can be converted to i64"
);
assert_eq!(
<(i32, i32)>::try_from(i).unwrap_err().to_string(), "Only TwoSmallInts can be converted to (i32, i32)"
);
assert_eq!(
<(i64, i64)>::try_from(i).unwrap_err().to_string(), "Only NamedBigInts can be converted to (i64, i64)"
);
assert_eq!(42u32, i.try_into().unwrap());
assert_eq!(&42u32, <_ as TryInto<&u32>>::try_into(&i).unwrap());
assert_eq!(
&mut42u32,
<_ as TryInto<&mut u32>>::try_into(&mut i).unwrap()
);
assert_eq!(
<()>::try_from(i).unwrap_err().to_string(), "Only Unit can be converted to ()"
);
let i = MixedInts::Unit;
assert_eq!(
i32::try_from(i).unwrap_err().to_string(), "Only SmallInt can be converted to i32"
);
assert_eq!(
i64::try_from(i).unwrap_err().to_string(), "Only NamedBigInt, UnsignedWithIgnoredField, NamedUnsignedWithIgnoredField can be converted to i64"
);
assert_eq!(
<(i32, i32)>::try_from(i).unwrap_err().to_string(), "Only TwoSmallInts can be converted to (i32, i32)"
);
assert_eq!(
<(i64, i64)>::try_from(i).unwrap_err().to_string(), "Only NamedBigInts can be converted to (i64, i64)"
);
assert_eq!(
u32::try_from(i).unwrap_err().to_string(), "Only Unsigned, NamedUnsigned can be converted to u32"
);
assert_eq!((), i.try_into().unwrap());
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-06-19)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.