musli_core/alloc/
mod.rs

1//! # Müsli Rust core allocation and collections library
2//!
3//! This library provides smart pointers and collections for managing allocated
4//! values. This is similar to the Rust [`alloc`][std-alloc] crate, it provides
5//! similar but more limited functionality. However it can do so safely using
6//! the Müsli-specific [`Allocator`] trait allowing these types to be used in
7//! `no_std` environments without requiring a nightly compiler or `unsafe`.
8//!
9//! [std-alloc]: rust_alloc
10
11mod to_owned;
12#[doc(inline)]
13pub use self::to_owned::ToOwned;
14
15mod allocator;
16#[doc(inline)]
17pub use self::allocator::Allocator;
18
19#[cfg(feature = "alloc")]
20mod system;
21#[cfg(feature = "alloc")]
22#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
23pub use self::system::{System, SystemAlloc};
24
25mod disabled;
26#[doc(inline)]
27pub use self::disabled::Disabled;
28
29mod string;
30pub(crate) use self::string::collect_string;
31#[doc(inline)]
32pub use self::string::{FromUtf8Error, String};
33
34mod vec;
35#[doc(inline)]
36pub use self::vec::Vec;
37
38mod boxed;
39#[doc(inline)]
40pub use self::boxed::Box;
41
42#[allow(clippy::module_inception)]
43mod alloc;
44#[doc(inline)]
45pub use self::alloc::Alloc;
46
47use core::fmt;
48
49/// An allocation error.
50#[derive(Debug)]
51pub struct AllocError;
52
53impl fmt::Display for AllocError {
54    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55        write!(f, "Failed to allocate memory")
56    }
57}
58
59impl core::error::Error for AllocError {}