artichoke / strftime-ruby

⏳ Ruby `Time#strftime` parser and formatter
https://crates.io/crates/strftime-ruby
MIT License
12 stars 0 forks source link

Use fallible allocation APIs #20

Closed lopopolo closed 2 years ago

lopopolo commented 2 years ago

For the implementation of Write for Vec<u8>, use Vec::try_reserve to try and allocate memory before copying a slice into the Vec. If a TryReserveError is returned, bubble that up to the caller instead of letting alloc do a process abort.

If an allocation fails, return Error::OutOfMemory.

This commit removes derive(Copy) from the error type in this crate because the inner TryReserveError in the OutOfMemory variant is not Copy.

lopopolo commented 2 years ago

Sorry to merge this change without pinging you @x-hgg-x. I wasn't sure you had accepted the invite yet. If you'd like to do a post-merge code review, I'm open to feedback on this PR.