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

Implement println! using nested format_args! #987

Merged
merged 1 commit into from
Jun 26, 2023

Conversation

tsoutsman
Copy link
Member

concat! prevents format_args! from capturing variables from the surrounding scope. Implementing println! using a nested format_args! removes this limitation allowing us to do the following:

let x = 3;
println!("{x}");

Similar to std::println!.

Also, the change does not impact performance.

`concat!` prevents `format_args!` from capturing variables from the
surrounding scope. Implementing `println!` using a nested `format_args!`
removes this limitation allowing us to do the following:
```rust
let x = 3;
println!("{x}");
```
Similar to `std::println!`.

Also, the change [does not impact performance][1].

[1]: rust-lang/rust#106824

Signed-off-by: Klimenty Tsoutsman <[email protected]>
Copy link
Member

@kevinaboos kevinaboos left a comment

Choose a reason for hiding this comment

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

Nice, I was wondering about doing that sort of variable capturing in custom format macros!

There are a few other places where we do this similar concat!() pattern, a few I can think of off the top of my head are early_printer, println_log!() in the deps app, etc. Would you mind submitting similar PR(s) for those?

@kevinaboos kevinaboos merged commit 2d6e8b4 into theseus-os:theseus_main Jun 26, 2023
2 checks passed
github-actions bot pushed a commit that referenced this pull request Jun 26, 2023
Our previous usage of `concat!()` prevents `format_args!`
from capturing variables from the surrounding scope.
Implementing `println!` using a nested `format_args!`
removes this limitation allowing us to do the following:
```rust
let x = 3;
println!("{x}");
```

Signed-off-by: Klimenty Tsoutsman <[email protected]> 2d6e8b4
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