At the moment we have an unstabilized allocations API in the std, so this is a temporary safe solution for a stable rust.
To create a vector you could use this code example: ``` use falliblealloc::vec::allocwith_size;
...
let vectorsize: usize = 10;
let maybevector = allocwithsize::
match maybe_vector {
Ok(vec) => println!("Created a vec with size 10"),
Err(error) => println!("Failed to create a vec, reason: {}", error)
}
As you could see, the maybe_vector has a
Result
Also it's possible to change the allocator used by crate with this code example: ``` use std::alloc::{GlobalAlloc, System, Layout};
struct MyAllocator;
unsafe impl GlobalAlloc for MyAllocator { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { System.alloc(layout) }
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
System.dealloc(ptr, layout)
}
}
static GLOBAL: MyAllocator = MyAllocator; ```