Skip to content

Add impl for TryFromSliceError#557

Merged
bors[bot] merged 1 commit intoknurling-rs:mainfrom
newAM:main
Aug 12, 2021
Merged

Add impl for TryFromSliceError#557
bors[bot] merged 1 commit intoknurling-rs:mainfrom
newAM:main

Conversation

@newAM
Copy link
Copy Markdown
Member

@newAM newAM commented Aug 11, 2021

This implements defmt::Format for TryFromSliceError which enables code like this:

use core::convert::TryInto;

let foo: [u8; 5] = [0, 1, 2, 3, 4];
let bar: u32 = u32::from_be_bytes(defmt::unwrap!(foo[1..2].try_into()));

When it fails it looks like this:

ERROR panicked at 'unwrap failed: foo [1 .. 2].try_into()'
error: `TryFromSliceError(())`

Which is similar to what it looks like on std targets with .unwrap()

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: TryFromIntError(())', src/main.rs:5:35

Copy link
Copy Markdown

@justahero justahero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

bors r+

@bors
Copy link
Copy Markdown
Contributor

bors Bot commented Aug 12, 2021

Build succeeded:

@bors bors Bot merged commit 9b82635 into knurling-rs:main Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants