| Crates.io | with_capacity_safe |
| lib.rs | with_capacity_safe |
| version | 0.4.2 |
| created_at | 2021-02-17 07:15:14.146467+00 |
| updated_at | 2021-12-03 07:06:25.191552+00 |
| description | A safer alternative to Vec::with_capacity with into_raw_parts which can be used from stable |
| homepage | |
| repository | https://github.com/dochy-ksti/with_capacity_safe |
| max_upload_size | |
| id | 356401 |
| size | 7,749 |
Vec::with_capacity(capacity) panics / aborts when the capacity is too large.
This is a safer alternative which reports Error using try_reserve_exact
//let's pretend this is an arbitrary number read from a broken file
let number_from_file : usize = 100_000_000_000_000;
//try to create a 100TB Vec
let result : Result<Vec<u8>, _> = vec_with_capacity_safe(number_from_file);
//An error is reported
assert!(result.is_err());
vec_into_raw_parts decomposes Vec into ts raw components.
1.57.0(stable)
0.4.2 TryReserve is stabilized at Rust 1.57.0
0.3.0
0.2.0