Extension trait generic over

I'm trying to create an extension method for &str that is generic over integer types because the end result is to return a tuple of ranges. However I'm having some issues with the calls to parse() and I'm not sure how to go forward from here. Here's a link to the playground.

You just need to add another bound on the impl because of the requirements on unwrap

impl<T> StrExt<T> for &str
where
    T: PartialOrd + FromStr + Debug,
    T::Err: Debug,
{
1 Like

Well that's... unexpected. I imagined it wold take some more tinkering with the code to make it work. By the way isn't there a way that allows me to call it like this? I thought it would be possible but the compiler doesn't seem to agree.

let ranges = "2-4,6-8".map_to_range_tuple::<u32>();

The range types don't implement FromStr which is why that doesn't work.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.