-
Notifications
You must be signed in to change notification settings - Fork 32
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
Make Display impl respect formatting parameters #58
Conversation
That looks very good to me! For the doc comments, I would say option 2 is the best looking one.
You're right about this being technically a breaking change, but I think it's really fine, for multiple reasons (it looks like I'm arguing, but it's really more about keeping them for reference just in case):
|
By the way, feel free to add yourself to the list of contributors in the README.md and Cargo.toml files, if you want. :) |
I did the same for matrices and realized i don't need macro recursion so i also replaced the recursive solution with iteration on vectors because it looks cleaner to me. Didn't bench perf - not sure if it matters for printing. Relatedly - matrices have two Display impls - for row-major and column-major - if perf doesn't matter, could be simplified into one by using Index. This PR solved the original issue i had but i am not sure all its effects are so desirable - e.g.: let v1 = Vec2::new(5.322, 6.464616);
let v2 = Vec2::new(-5.0003, -0.0);
println!("{1:6.2} | {0:6.2}", v1, v2); aligns the individual elements which might be surprising if people want to align the whole result instead. (Sry no example in comment, GitHub removes consecutive spaces fsr) Not sure what other similar crates do - your thoughts? |
I think performance will be just fine, I would expect the bottleneck to be the actual file/console I/O that takes place.
I think this is very situational. In the extremely rare (I suppose) case where people do want this, I think it would be easy for them to write their own function for that. This looks great to me. Would you like to add anything before I merge this? :) |
Hmm, they might not impl Display but they do impl Debug... ...which appears to have the same "issue" as this code, same with tuple structs. So if std is ok with this behavior, i guess it's fine here.
Nope, i think it's done. |
Great! I'll merge and push a new version. Thanks. |
Fixes #57
I don't think there's a cleaner (without another macro) way to handle the repetition.
I used
fmt_prefix
but i noticed you prefer naming without underscores, should i rename it tofmtprefix
?Not sure how to proceed with the doc comments:
Option 1: keep it as it: e.g. "Displays the vector, formatted as
({}, {}, {})
." - it wouldn't be completely right since it now passes the formatting params correctly. Which actually reminds me that this PR is technically a breaking change.Option 2: e.g. "Displays the vector, formatted as
({...}, {...}, {...})
where...
are the actual formatting parameters." - would pass this into the macro as$fmt
in addition to$fmt_prefix
.Option 3: make it somewhat vague like "Displays the vector, numbers are separated by commas." - would also need a special case for the vectors with prefixes.
Thoughts?
Also when we agree how to do this, I should do the same for matrices.