Skip to content

decoder: add Frame::fragments() and Frame::display_fragments() #966

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

darkwater
Copy link

One cool possibility with defmt is a log viewer that can do more than just display static text, eg. change number representations on the fly. These two methods should make doing something like that a bit easier.

Copying from the docs I put on display_fragments():


Returns an iterator over the fragments of the message contained in this log frame.

Collecting this into a String will yield the same result as Self::display_message, but
this iterator will yield interpolated fragments on their own. For example, the log:

defmt::info!("foo = {}, bar = {}", 1, 2);

Will yield the following strings:

vec!["foo = ", "1", ", bar = ", "2"]

Note that nested fragments will not yield separately:

defmt::info!("foo = {}", Foo { bar: 1 });

Will yield:

vec!["foo = ", "Foo { bar: 1 }"]

This iterator yields the same fragments as Self::fragments, so you can zip them
together to get both representations.


This is quite limited in that it doesn't go into nested fragments, but could already enable some limited extra functionality with minimal effort.

Haven't tested on an actual project yet, intend to do that tomorrow.

@darkwater darkwater force-pushed the main branch 2 times, most recently from 7b06e3f to 97a918d Compare May 14, 2025 18:30
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.

1 participant