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

Better string formatting #129

Open
dcoles opened this issue Jan 23, 2024 · 1 comment
Open

Better string formatting #129

dcoles opened this issue Jan 23, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@dcoles
Copy link
Collaborator

dcoles commented Jan 23, 2024

As a developer, there are currently three main options for formatting strings in Flipper apps:

Safe Expressiveness Binary size overhead
std::fmt High High1
ufmt Low Low
sys::furi_string_printf High None2

Using std::fmt is the most flexible and familiar option for developers, but it can add 10+ KB to the overall binary size simply by formatting a single string. While this may be a reasonable trade-off made by an app developer, it's not something we can impose on all users of the flipperzero crates.

Enter ufmt which has substantially lower binary overhead, but comes at the expense of expressiveness (no padding/alignment/formatting options, no support for floats) and requires implementing the non-standard ufmt::uDisplay and ufmt::uWrite traits.

Finally there is the built-in sys::furi_string_printf C function, which has no binary-size overhead (it's provided by the Furi runtime), but is problematic to use in Rust because it has a variadic-based interface which is both unsafe and difficult to support in Rust (Rust currently only has limited support for C-variadic functions).

It would be nice to provide an option somewhere in the middle.

Footnotes

  1. See Use ufmt crate for print! macros #48 and Formatting is Unreasonably Expensive for Embedded Rust

  2. Provided by Furi runtime

@dcoles dcoles added the enhancement New feature or request label Jan 23, 2024
@dcoles dcoles self-assigned this Jan 23, 2024
@dcoles
Copy link
Collaborator Author

dcoles commented Jan 23, 2024

One thought that came to mind was to provide a mechanism for safely using printf-style functions from Rust (e.g. a procedural macro that generates safe printf calls).

Another possibility would be for us to provide Display / Write traits that allow printf-style calls to be made internally (while still providing a safe external interface).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant