with_capacity_safe 0.4.2

A safer alternative to Vec::with_capacity with into_raw_parts which can be used from stable
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::{vec_with_capacity_safe};

#[test]
fn it_works(){
    let r = vec_with_capacity_safe::<i32>(usize::MAX);
    match r{
        Err(_) =>{},
        _ => unreachable!(),
    };
    //isize_max以上でCapacityOverlowって書いてあるけど、そうでもないみたいね https://doc.rust-lang.org/std/collections/enum.TryReserveError.html
    let r = vec_with_capacity_safe::<u8>(usize::MAX);
    match r {
        Err(_) => {}
        _ => unreachable!(),
    };

}