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

Rust macros and types cleanup #3951

Merged
merged 8 commits into from
Jun 19, 2024
Merged

Rust macros and types cleanup #3951

merged 8 commits into from
Jun 19, 2024

Conversation

matejcik
Copy link
Contributor

building on top of #3938 for the dbg_print! macros

  • use Rust's built-in CStr in favor of a stand-alone crate
  • make use of c"" string literals in favor of cstr! macro
  • introduce uformat! convenience macro that will return (by default) a ShortString with the formatting result.
    • unwraps internally because otherwise we just write unwrap!(uformat!()) everywhere, that's pure noise.
    • if you want to handle errors, create a String instance and invoke uwrite! on it manually
  • unify all code to use a ShortString instead of picking a size ad hoc and carrying multiple copies of String<N>
    • this saves a meager ~1 kB of flash
  • centralize #[macro_use] to exactly one place (the macros module in root). Import all other macros as needed (so things like obj_type! are explicitly imported from micropython::macros. Seems just plain nicer.)
  • extend dbg_print!() functionality to places that don't have micropython, such as bootloader-emu (but note that you have to enable the debug feature)

@matejcik matejcik requested a review from prusnak as a code owner June 14, 2024 12:08
@matejcik matejcik requested review from cepetr and mmilata and removed request for prusnak June 14, 2024 12:08
Copy link

core UI changes device test click test persistence test
T2T1 Model T test(screens) main(screens) test(screens) main(screens) test(screens) main(screens)
T2B1 Safe 3 test(screens) main(screens) test(screens) main(screens) 2724
T3T1 test(screens) main(screens) test(screens) main(screens) test(screens) main(screens)
All main(screens)

@obrusvit
Copy link
Contributor

Feel free to include #3953

@obrusvit
Copy link
Contributor

Do you think we could achieve formatting translated template strings with uformat!?
Something like this would be desirable:

let text = TR::reset__select_word_x_of_y_template.map_translated(|s| {
    uformat!(s, n_choice, n_words)
});

ufmt complains with error: expected string literal

@matejcik
Copy link
Contributor Author

Do you think we could achieve formatting translated template strings with uformat!?
Something like this would be desirable:

we can't because the format literals are parsed at compile-time.
we will need to find another library, or write our own

@matejcik
Copy link
Contributor Author

Feel free to include #3953

very nice, cherry-picked as d0d6780

Copy link
Member

@mmilata mmilata left a comment

Choose a reason for hiding this comment

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

nice cleanup

@cepetr cepetr force-pushed the cepetr/rsod-fix branch from 640dee6 to cf2d942 Compare June 17, 2024 14:31
@cepetr cepetr requested a review from andrewkozlik as a code owner June 17, 2024 14:31
Base automatically changed from cepetr/rsod-fix to main June 17, 2024 14:57
matejcik and others added 8 commits June 18, 2024 13:34
@matejcik matejcik force-pushed the matejcik/rust-macro branch from b95c2c2 to 8846620 Compare June 18, 2024 11:35
@andrewkozlik andrewkozlik removed their request for review June 18, 2024 13:13
@matejcik matejcik merged commit a01a787 into main Jun 19, 2024
80 of 84 checks passed
@matejcik matejcik deleted the matejcik/rust-macro branch June 19, 2024 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants