I'm pleasantly surprised that fallible allocation fits in so well with Rust's design (though it requires a different standard library, which is fine and perhaps even preferable). I didn't think it was possible when the language was being developed. But it seems to work great!
Conversation
This Tweet was deleted by the Tweet author. Learn more
Doesn't that depend on the types being initialized?
1
This Tweet was deleted by the Tweet author. Learn more
This Tweet was deleted by the Tweet author. Learn more
This Tweet was deleted by the Tweet author. Learn more
Store the value to be allocated on the stack, then move it into the heap once the allocation succeeds? This is how Box::new works.
3
This Tweet was deleted by the Tweet author. Learn more
Why does it need to be exposed to safe Rust? If allocation fails, a fallible version of Box::new could just give you your object back.
2
6
Similarly, Vec::push and similar methods on collections can return the provided value on failure.
It was discussed years ago and implemented outside the standard library. It just seems no one got around to figuring out how to integrate it into the standard libraries.
