rust-lang / wg-allocators

Home of the Allocators working group: Paving a path for a standard set of allocator traits to be used in collections!
http://bit.ly/hello-wg-allocators
205 stars 9 forks source link

Add `Result` to `core::alloc` #56

Closed TimDiekmann closed 4 years ago

TimDiekmann commented 4 years ago

What to you think about adding a Result alias to the alloc module?

pub type Result<T, E = AllocErr> = core::result::Result<T, E>;

or even

pub type Result<T = MemoryBlock, E = AllocErr> = core::result::Result<T, E>;
SimonSapin commented 4 years ago

My the E parameter? There isn’t one in std::io::Result or std::thread::Result. Shouldn’t users that would make it non-default be using result::Result instead?

TimDiekmann commented 4 years ago

I don't have a strong opinion on the default parameter, but IMO they are missing in io::Result, thread::Result, and fmt::Result.

Anyway, if I use a defaulted Result, I always use the module name as well for clarity:

use io;
fn foo() -> io::Result
TimDiekmann commented 4 years ago

Inspecting io::Result again:

This typedef is generally used to avoid writing out io::Error directly and is otherwise a direct mapping to Result.

Do we also want to rename alloc::AllocErr to alloc::Error?

SimonSapin commented 4 years ago

There’s also alloc::LayoutErr.

TimDiekmann commented 4 years ago

Oh, right :disappointed:

Amanieu commented 4 years ago

I don't feel that Result<T, AllocErr> is sufficiently widely used to justify making a type alias.