Skip to main content

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, GlobalAllocator};
18
19#[cfg(feature = "alloc")]
20mod global;
21#[cfg(feature = "alloc")]
22#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
23#[doc(inline)]
24pub use self::global::{Global, GlobalAlloc};
25
26mod string;
27pub(crate) use self::string::collect_string;
28#[doc(inline)]
29pub use self::string::{FromUtf8Error, String};
30
31mod vec;
32#[doc(inline)]
33pub use self::vec::Vec;
34
35mod boxed;
36#[doc(inline)]
37pub use self::boxed::Box;
38
39#[allow(clippy::module_inception)]
40mod alloc;
41#[doc(inline)]
42pub use self::alloc::Alloc;
43
44use core::fmt;
45
46/// An allocation error.
47#[derive(Debug, PartialEq, Eq)]
48pub struct AllocError;
49
50impl fmt::Display for AllocError {
51    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52        write!(f, "Failed to allocate memory")
53    }
54}
55
56impl core::error::Error for AllocError {}