Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There is some minimal support for fallible allocation through the try_reserve method on various collections. See https://github.com/rust-lang/rust/issues/48043 for more information.

Other than that, there is ongoing work for custom allocator support in collections: https://github.com/rust-lang/rust/issues/42774. Maybe that's what you meant with tracking the allocators at the type level?

It's of course also possible to create own fallible collection types, for example as a wrapper around the normal liballoc and try_reserve.



But none of the standard libraries expose those failures. Did you end up writing an std_lib?


The try_reserve method is exposed on all collection types, e.g. [1],but it is still unstable.

[1]: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.try...

I did not write my own stdlib since I didn't need it yet (the blog has no heap allocation yet). And I think infallible allocation is good enough for the beginning.

But I think it should be possible to create a fallible wrapper library around liballoc quite easily. We only need an appropriate call to try_reserve for every wrapped function. For example, `push` would do a `try_reserve(1)` before calling the push function of liballoc.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: