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

Fix format width calculation in no_std environments #1196

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

matteocarnelos
Copy link

When disabling the std feature, the calculation of the formatted width of the values is skipped and replaced by a fixed number (i.e. 4). This causes the output to be wrongly formatted when printing. I fixed this issue by implementing a custom writer, that implements the fmt::Write trait, and counts the number of character in the write_str() method, instead of printing them.

How to reproduce the issue

Cargo.toml

[dependencies]
nalgebra = { version = "0.32", default-features = false, features = ["macros"] }

main.rs

use nalgebra::matrix;

fn main() {
    println!("{}", matrix![1, 2, 3]);
}

Output:

  ┌                ┐
  │ 1 2 3 │
  └                ┘

How to test the fix

Cargo.toml

[dependencies]
nalgebra = { version = "0.32", default-features = false, features = ["macros"] }
[patch.crates-io]
nalgebra = { git = "https://github.com/matteocarnelos/nalgebra" }

main.rs

use nalgebra::matrix;

fn main() {
    println!("{}", matrix![1, 2, 3]);
}

Output:

  ┌       ┐
  │ 1 2 3 │
  └       ┘

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.

None yet

1 participant