Skip to content

Commit

Permalink
Merge #581
Browse files Browse the repository at this point in the history
581: Add impl for alloc::Layout r=Urhengulas a=newAM

This is useful for displaying the layout argument in the `alloc_error_handler`, e.g.

```rs
#[alloc_error_handler]
fn oom(layout: Layout) -> ! {
    defmt::error!("OOM {}", layout):

    loop {
        cortex_m::asm::bkpt();
    }
}
```

Co-authored-by: Alex Martens <alexmgit@protonmail.com>
  • Loading branch information
bors[bot] and newAM authored Sep 16, 2021
2 parents fb85bc1 + 4c6122e commit 845b443
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/impls/core_/alloc_.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use core::alloc;

use super::*;

impl Format for alloc::Layout {
fn format(&self, fmt: Formatter) {
crate::write!(
fmt,
"Layout {{ size: {}, align: {} }}",
self.size(),
self.align()
);
}
}
1 change: 1 addition & 0 deletions src/impls/core_/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! We generally keep the type parameter trait bounds in case it becomes possible to use this
//! later, without making a backwards-incompatible change.

mod alloc_;
mod array;
mod num;
mod ops;
Expand Down

0 comments on commit 845b443

Please sign in to comment.