Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add impl for TryFromSliceError #557

Merged
merged 1 commit into from
Aug 12, 2021
Merged

Add impl for TryFromSliceError #557

merged 1 commit into from
Aug 12, 2021

Conversation

newAM
Copy link
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
Contributor

@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
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