Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use anyhow::{anyhow, Ok, Result};
- struct MyType;
- trait MyTrait1: Sized {
- fn foo(my_type: MyType) -> Result<Self> {
- Ok(Self::try_from_my_type(my_type)?)
- }
- fn try_from_my_type(my_type: MyType) -> Result<Self>;
- }
- impl<T> MyTrait1 for T
- where
- T: Sized + TryFrom<MyType>,
- {
- fn try_from_my_type(my_type: MyType) -> Result<Self> {
- Self::try_from(my_type).map_err(|_| anyhow!("Failed to convert"))
- }
- }
- trait MyTrait2: Sized {
- fn foo(my_type: MyType) -> Result<Self> {
- Ok(Self::try_from_my_type(my_type)?)
- }
- fn try_from_my_type(my_type: MyType) -> Result<Self>;
- }
- impl<T> MyTrait2 for T
- where
- T: Sized + From<MyType>,
- {
- fn try_from_my_type(my_type: MyType) -> Result<Self> {
- Ok(Self::from(my_type))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement