-
Notifications
You must be signed in to change notification settings - Fork 249
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
Add HumanCount and template keys to print position and length with co… #340
Conversation
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
use fmt::Write; | ||
|
||
let num = self.0.to_string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's almost certainly a more efficient implementation. Let me know if I should work on this or benchmark it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, not sure there's an obviously more efficient implementation.
I do think the backwards counting loop variable is a little confusing, how about changing the loop to just use for (i, c) in num.chars().enumerate()
and rename your current i
to len
(immutable), then maybe add a binding for let pos = len - i;
or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I think the new version is a bit simpler. Another idea is to iterate in reverse, but then that requires reversing the output string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mostly looks good to me, one style nit and I'll be happy to merge it!
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
use fmt::Write; | ||
|
||
let num = self.0.to_string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, not sure there's an obviously more efficient implementation.
I do think the backwards counting loop variable is a little confusing, how about changing the loop to just use for (i, c) in num.chars().enumerate()
and rename your current i
to len
(immutable), then maybe add a binding for let pos = len - i;
or something?
…mmas. #339
Motivation and trade-offs described in the issue. This was quite straightforward. Already using in alan-turing-institute/uatk-aspics@7332180, demo: