swc_allocator/lib.rs
1//! Allocator for swc.
2//!
3//! # Features
4//!
5//! - `scoped`: Enable `scoped` mode.
6//!
7//! # Modes
8//!
9//! ## Default mode
10//!
11//! In default mode, [crate::boxed::Box] and [crate::vec::Vec] are identical to
12//! the original types in [std].
13//!
14//! ## Scoped mode
15//!
16//! - You need to enable `scoped` feature to use this mode.
17//!
18//! In `scoped` mode you can use [FastAlloc] to make [crate::boxed::Box] and
19//! [crate::vec::Vec] very fast.
20//!
21//! In this mode, you need to be careful while using [crate::boxed::Box] and
22//! [crate::vec::Vec]. You should ensure that [Allocator] outlives all
23//! [crate::boxed::Box] and [crate::vec::Vec] created in the scope.
24//!
25//! Recommened way to use this mode is to wrap the whole operations in
26//! a call to [Allocator::scope].
27
28#![allow(clippy::needless_doctest_main)]
29#![cfg_attr(docsrs, feature(doc_cfg))]
30#![cfg_attr(
31 feature = "nightly",
32 feature(allocator_api, fundamental, with_negative_coherence, box_into_inner)
33)]
34#![deny(missing_docs)]
35#![allow(clippy::derivable_impls)]
36
37// TODO: Add types back
38// pub use crate::types::*;
39
40pub mod allocators;
41pub mod api;
42mod types;
43mod util;
44
45/// This expands to the given tokens if the `nightly` feature is enabled.
46#[cfg(feature = "nightly")]
47#[macro_export]
48macro_rules! nightly_only {
49 (
50 $($item:item)*
51 ) => {
52 $(
53 #[cfg_attr(docsrs, doc(cfg(feature = "nightly")))]
54 $item
55 )*
56 };
57}
58
59/// This expands to the given tokens if the `nightly` feature is enabled.
60#[cfg(not(feature = "nightly"))]
61#[macro_export]
62macro_rules! nightly_only {
63 (
64 $($item:item)*
65 ) => {};
66}