Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Why do crates overload the std::result::Result type? | tree_ds
So I was trying to use the tree_ds crate for a tree datastructure and found the crate is “overloading” the Result keyword to represent more of an Option, since the crate’s error types are private. The crate also expects you to use it via a pelude import, which is why I didn’t notice this at first.
use tree_ds::prelude::*;
...
//Result after prelude import
fn do_stuff() -> Result<T> {}
//How to get standard Result<T, E> back:
fn do_stuff() -> std::result::Result<T, E> {}
//Restricting the prelude import fixes this
use tree_ds::prelude{Node, Tree};
Restricting the prelude
import fixes this, (not sure that is really workable in the long run, and sort of defeats the point of a prelude, doesn’t it?), but I am a bit curious why one would design an API this way, especially because the crate only really exposes the prelude
to import?
5 posts - 3 participants
🏷️ rust_feed