3 ms·
That code sample is really helpful, thanks. But doesn't that seem kind of redundant? Box and std containers are great as is, except for the one line that abort
by acconsta 11y ago
That code sample is really helpful, thanks.
But doesn't that seem kind of redundant? Box and std containers are great as is, except for the one line that aborts on OOM. Would it be possible to use traits to choose OOM behavior at compile time?
To be clear, this isn't just important for embedded. A production database or web server should be able to handle an allocation failure without blowing up the whole process.
And I'm glad there's some talk about a standard allocator trait. I'll look for the relevant issue.
- dbaupp 11y agoThere could definitely be an alternate method on `Box` that returned Result, but I don't think this is so feasible for containers which allocate in many places and so would require duplicating most of the API, however there may be some tricks that work. https://github.com/rust-lang/rfcs/issues/538 https://github.com/rust-lang/rfcs/issues/538 covers the allocator stuff.
- acconsta 11y agoRight, duplicating every method that allocates also isn't very elegant. But could Box and containers be polymorphic on an OOM handling trait? Alternatively, one could imagine an OOM-safe container that returns results, and a convenience wrapper class that unwraps them. That might harm efficient code generation though.