Why isn't `Result: From`?

⚓ Rust    📅 2026-02-22    👤 surdeus    👁️ 1      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Why isn't `Result: From`?

My question is in the title. Let me maybe explain why I was expecting it to be implemented.

The std::ops::Div trait looks like this:

pub trait Div<Rhs = Self> {
    type Output;
    fn div(self, rhs: Rhs) -> Self::Output;
}

The Output could be a Result, perhaps because the implementation checks for division by zero.

I was naively expecting that I could write code that is generic over the return type of div() being a T or a Result<T, E>, simply via a bound of Output: Into<Result<T, E>>, E: Error, and by banking on Result<T, Infallible>: From<T>.

I was surprised to learn that this last trait is not implemented. So why isn't there a blanket implementation for turning a T into a Result<T, Infallible>, like we have it for Option<T>?

2 posts - 2 participants

Read full topic

🏷️ Rust_feed