4 ms·
The allocation most built in to the language is https://doc.rust-lang.org/std/heap/trait.Alloc.html https://doc.rust-lang.org/std/heap/trait.Alloc.html and that
by dbaupp 9y ago
The allocation most built in to the language is https://doc.rust-lang.org/std/heap/trait.Alloc.html https://doc.rust-lang.org/std/heap/trait.Alloc.html and that returns a Result. Some std APIs like Box and Vec do just panic/abort on allocation failure (although that's changing), but these are all library types defined in std, neither the language itself nor the lower level core library (more relevant to embedded platforms) do any allocation.
- muricula 9y agoUnless I'm mistaken, the little-b `box` keyword panics on failure. Isn't that required to construct a type in place in heap memory?
- steveklabnik 9y agoThe box keyword isn't in stable Rust yet, and isn't even "the box keyword" anymore. https://github.com/rust-lang/rfcs/blob/master/text/1228-placement-left-arrow.md https://github.com/rust-lang/rfcs/blob/master/text/1228-plac... is the latest RFC I believe, but even that I believe is changing since the latest allocator API work, though I'm not 100% sure.
- dbaupp 9y agoMy understanding is that the latest RFCes touching that syntax (not sure if they're implemented) have it overloaded with traits, and I would guess/hope that it's possible to implement those traits in a way that is fallible (e.g. hypothetically 'impl BoxSyntax for Result<Box<T>, AllocationError>').