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 global;
21#[cfg(feature = "alloc")]
22#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
23pub use self::global::{Global, GlobalAlloc};
24
25#[doc(hidden)]
26#[cfg(feature = "alloc")]
27#[deprecated = "`System` has been renamed to `Global`"]
28pub type System = Global;
29
30#[doc(hidden)]
31#[cfg(feature = "alloc")]
32#[deprecated = "`SystemAlloc` has been renamed to `GlobalAlloc`"]
33pub type SystemAlloc<T> = GlobalAlloc<T>;
34
35mod disabled;
36#[doc(inline)]
37pub use self::disabled::Disabled;
38
39mod string;
40pub(crate) use self::string::collect_string;
41#[doc(inline)]
42pub use self::string::{FromUtf8Error, String};
43
44mod vec;
45#[doc(inline)]
46pub use self::vec::Vec;
47
48mod boxed;
49#[doc(inline)]
50pub use self::boxed::Box;
51
52#[allow(clippy::module_inception)]
53mod alloc;
54#[doc(inline)]
55pub use self::alloc::Alloc;
56
57use core::fmt;
58
59/// An allocation error.
60#[derive(Debug, PartialEq, Eq)]
61pub struct AllocError;
62
63impl fmt::Display for AllocError {
64 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
65 write!(f, "Failed to allocate memory")
66 }
67}
68
69impl core::error::Error for AllocError {}