Currently, I have a trait like this:
trait Trait
where
Self: Sized,
{
fn try_form_u8(num: u8) -> Option<Self>;
fn try_from_str<T: AsRef<str>>(s: &T) -> Option<Self>;
// ...
}
Optimally, I want to define it like simliar to this, in order to not have try_from_* methods outside of a TryFrom implementation:
trait Trait: for<T: AsRef<str>> TryFrom<u8> + TryFrom<T>
where
Self: Sized
{
// ...
}
I couldn't find a way to accomplish that and finally came across this thread: Can a trait have a supertrait that is parameterized by a generic?
I wonder how to continue from here. Should I use the unconventional try_from_str method or is there a better way to express what is needed here?
Note that in my original code I have Path instead of str, which could eliminate some special solutions, but I would still like to know them if there are any nice solution!