fallible_alloc/
lib.rs

1//! # Fallible rust stable std collections allocations
2//!
3//! While the failable allocation API for std is being stabilized
4//! there should be a solution, so that's why this crate exists.
5//!
6//! # Usage example
7//!
8//! To create a vector you could use this code example:
9//! ```rust
10//! use fallible_alloc::vec::alloc_with_size;
11//!
12//! let vector_size: usize = 10;
13//! let maybe_vector = alloc_with_size::<f64>(vector_size);
14//!
15//! match maybe_vector {
16//!   Ok(vec) => println!("Created a vec with size 10"),
17//!   Err(error) => println!("Failed to create a vec, reason: {}", error)
18//! }
19//! ```
20//! As you could see, the maybe_vector has a Result<[`Vec<T>`], [AllocError](crate::alloc_error::AllocError)> type,
21//! so now it's possible to handle a part of allocation errors.
22//!
23//! Also it's possible to change the allocator used by crate with this code example:
24//! ```rust
25//! use std::alloc::{GlobalAlloc, System, Layout};
26//!
27//! struct MyAllocator;
28//!
29//! unsafe impl GlobalAlloc for MyAllocator {
30//!     unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
31//!         System.alloc(layout)
32//!     }
33//!
34//!     unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
35//!         System.dealloc(ptr, layout)
36//!     }
37//! }
38//!
39//! #[global_allocator]
40//! static GLOBAL: MyAllocator = MyAllocator;
41//! ```
42
43#![deny(missing_docs)]
44#![deny(missing_doc_code_examples)]
45#![doc(html_root_url = "https://docs.rs/fallible_alloc/0.2.0")]
46
47pub mod alloc_error;
48pub mod box_ptr;
49mod util;
50pub mod vec;