|
8 | 8 | //! via their type parameter `N`. This means that you can instantiate a `heapless` data structure on
|
9 | 9 | //! the stack, in a `static` variable, or even in the heap.
|
10 | 10 | //!
|
11 |
| -//! There is a feature gate `const-fn` which enables the nightly `const_fn` feature. |
12 |
| -//! You can enable it in `Cargo.toml`. |
13 |
| -//! |
14 |
| -//! ```text |
15 |
| -//! # Cargo.toml |
16 |
| -//! ... |
17 |
| -//! [dependencies] |
18 |
| -//! heapless = { version = "0.4.0", features = ["const-fn"] } |
19 |
| -//! ... |
20 |
| -//! |
21 |
| -//! ``` |
22 |
| -//! When enabled, you can use most `new` methods to initialize `static` |
23 |
| -//! variables at compile time. |
24 |
| -//! |
25 |
| -//! |
26 | 11 | //! ```
|
27 | 12 | //! use heapless::Vec; // fixed capacity `std::Vec`
|
28 | 13 | //! use heapless::consts::U8; // type level integer used to specify capacity
|
|
38 | 23 | //! // work around
|
39 | 24 | //! static mut XS: Option<Vec<u8, U8>> = None;
|
40 | 25 | //! unsafe { XS = Some(Vec::new()) };
|
| 26 | +//! let xs = unsafe { XS.as_mut().unwrap() }; |
41 | 27 | //!
|
42 |
| -//! unsafe { XS.as_mut().unwrap().push(42) }; |
43 |
| -//! unsafe { assert_eq!(XS.as_mut().unwrap().pop(), Some(42)) }; |
| 28 | +//! xs.push(42); |
| 29 | +//! assert_eq!(xs.pop(), Some(42)); |
44 | 30 | //!
|
45 | 31 | //! // in the heap (though kind of pointless because no reallocation)
|
46 | 32 | //! let mut ys: Box<Vec<u8, U8>> = Box::new(Vec::new());
|
|
69 | 55 | //! queue
|
70 | 56 | //! - [`String`](struct.String.html)
|
71 | 57 | //! - [`Vec`](struct.Vec.html)
|
| 58 | +//! |
| 59 | +//! |
| 60 | +//! In order to target the Rust stable toolchain, there are some feature gates. |
| 61 | +//! The features need to be enabled in `Cargo.toml` in order to use them. |
| 62 | +//! Once the underlaying features in Rust are stable, |
| 63 | +//! these feature gates might be activated by default. |
| 64 | +//! |
| 65 | +//! Example of `Cargo.toml`: |
| 66 | +//! |
| 67 | +//! ```text |
| 68 | +//! ... |
| 69 | +//! [dependencies] |
| 70 | +//! heapless = { version = "0.4.0", features = ["const-fn"] } |
| 71 | +//! ... |
| 72 | +//! |
| 73 | +//! ``` |
| 74 | +//! |
| 75 | +//! Currently the following features are availbale and not active by default: |
| 76 | +//! |
| 77 | +//! - `"const-fn"` -- Enable the nightly `const_fn` feature and make most `new` methods `const`. |
| 78 | +//! This way they can be used to initialize static memory at compile time. |
| 79 | +//! |
| 80 | +
|
72 | 81 |
|
73 | 82 | #![allow(warnings)]
|
74 | 83 | #![deny(missing_docs)]
|
|
0 commit comments