3 ms·
Could you give a more complete example? I see the type signature for the function you're proposing, but I still don't understand what is supposed to replace .un
by dietrichepp 4y ago
Could you give a more complete example? I see the type signature for the function you're proposing, but I still don't understand what is supposed to replace .unwrap() on the inside of the function.
- rowanG077 4y agoThe "fix" would be to return a Result. Which is a sum of an error and the type you want to return.
- dietrichepp 4y agoYou can't return an Infallible, though, because it has no variants. You still need to do something at the point of unwrap().
- Macha 4y agoBut again, the function cannot fail. It could return a Result<Vec2, Infallible>, I guess, but then you're just pushing the unwrap to caller without any need to.
- rowanG077 4y agoThat's the entire point of the OP. That it can't fail so you might as well call unwrap.
- game-of-throws 4y agoYou'd pair it with something like this https://docs.rs/unwrap-infallible/ https://docs.rs/unwrap-infallible/
- dietrichepp 4y agoI don't see how that would work. d[0..4].try_into() The type of the result is something like: Result<[u8; 4], TryFromSliceError> How do I convert that into Result<[u8; 4], Infallible> As far as I can tell, Infallible is there because you're implementing a trait which returns an error, but you don't have an error to return at all.
- game-of-throws 4y agoIn jacobr1's comment we already have a way to get a Result<_, Infallible>. But converting a slice to an array returns a real error type, so my comment wouldn't apply. For your case just stick with `.try_into().unwrap()`. It's the easiest way. Unless of course someone on crates.io made a fancy crate with const generics.