use core::convert::Infallible; use core_ext::convert::TryTo; // wrapper type struct W(pub T); impl TryTo for W {} struct A(u8); impl TryFrom> for A { type Error = Infallible; fn try_from(value: W) -> Result { Ok(Self(value.0)) } } struct B(u8); impl TryFrom for B { type Error = Infallible; fn try_from(value: A) -> Result { Ok(B(value.0 + 1)) } } struct C(u8); impl TryFrom for C { type Error = Infallible; fn try_from(value: B) -> Result { Ok(Self(value.0 + 1)) } } #[cfg(test)] mod snapshots { use crate::*; #[test] fn test_try_to() -> Result<(), Infallible> { struct Type(u8); impl TryFrom> for Type { type Error = Infallible; fn try_from(value: W) -> Result { Ok(Type(value.0)) } } insta::assert_yaml_snapshot!(W(2_u8).try_to::()?.0); Ok(()) } #[test] fn test_try_to_chain() -> Result<(), Infallible> { impl TryTo for A {} impl TryTo for B {} insta::assert_yaml_snapshot!(W(0_u8).try_to::()?.0); insta::assert_yaml_snapshot!( W(1_u8) .try_to::()? .try_to::()? .try_to::()? .0 ); Ok(()) } }