Skip to content

Commit f6fa1cf

Browse files
bors[bot]jannic
andauthored
Merge #64
64: Allow and document usage with stable rust r=thejpster a=jannic Co-authored-by: Jan Niehusmann <jan@gondor.com>
2 parents e53aba8 + e4d2ae7 commit f6fa1cf

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
- Updated `linked_list_allocator` dependency to 0.10.5, which allows
11+
compiling with stable rust.
12+
1013
## [v0.5.0] - 2022-12-06
1114

1215
### Changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ critical-section = "1.0"
2828

2929
[dependencies.linked_list_allocator]
3030
default-features = false
31-
version = "0.10.4"
31+
version = "0.10.5"
3232
features = ["const_mut_refs"]
3333

3434
[dev-dependencies]

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,49 @@
11
[![crates.io](https://img.shields.io/crates/d/embedded-alloc.svg)](https://crates.io/crates/embedded-alloc)
22
[![crates.io](https://img.shields.io/crates/v/embedded-alloc.svg)](https://crates.io/crates/embedded-alloc)
3+
![Minimum Supported Rust Version](https://img.shields.io/badge/rustc-1.68+-blue.svg)
34

45
# `embedded-alloc`
56

67
> A heap allocator for embedded systems.
78
8-
Note that using this as your global allocator requires nightly Rust.
9+
Note that using this as your global allocator requires Rust 1.68 or later.
10+
(With earlier versions, you need the unstable feature `#![feature(default_alloc_error_handler)]`)
911

1012
This project is developed and maintained by the [Cortex-M team][team].
1113

1214
## Example
1315

14-
For a usage example, see `examples/global_alloc.rs`.
16+
Starting with Rust 1.68, this crate can be used as a global allocator on stable Rust:
17+
18+
```rust
19+
#![no_std]
20+
#![no_main]
21+
22+
extern crate alloc;
23+
24+
use cortex_m_rt::entry;
25+
use embedded_alloc::Heap;
26+
27+
#[global_allocator]
28+
static HEAP: Heap = Heap::empty();
29+
30+
#[entry]
31+
fn main() -> ! {
32+
// Initialize the allocator BEFORE you use it
33+
{
34+
use core::mem::MaybeUninit;
35+
const HEAP_SIZE: usize = 1024;
36+
static mut HEAP_MEM: [MaybeUninit<u8>; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE];
37+
unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) }
38+
}
39+
40+
// now the allocator is ready types like Box, Vec can be used.
41+
42+
loop { /* .. */ }
43+
}
44+
```
45+
46+
For a full usage example, see `examples/global_alloc.rs`.
1547

1648
## [Documentation](https://docs.rs/embedded-alloc)
1749

0 commit comments

Comments
 (0)