79690285

Date: 2025-07-04 13:53:07
Score: 0.5
Natty:
Report link

Thanks to the help I received in the comments I understood that maybe I was being too clever with the default trait method and the blanket impl. I could achieve the same in a much simpler way just by moving the method implementation to the trait impl:

pub trait IntoMyError {
  fn into_my_err(self, id: String) -> MyError;
}

impl<T: Into<anyhow::Error>> IntoMyError for T {
  fn into_my_err(self, id: String) -> MyError {
    MyError {
      id,
      kind: MyErrorKind::from(anyhow::Error::from(self)),
    }
  }
}
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Haf