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

Add HumanCount and template keys to print position and length with co… #340

Merged
merged 2 commits into from Dec 30, 2021

Conversation

dabreegster
Copy link
Contributor

…mmas. #339

Motivation and trade-offs described in the issue. This was quite straightforward. Already using in alan-turing-institute/uatk-aspics@7332180, demo:
Screenshot from 2021-12-30 17-26-30

fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use fmt::Write;

let num = self.0.to_string();
Copy link
Contributor Author

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

Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Collaborator

@djc djc left a 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();
Copy link
Collaborator

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?

@djc djc merged commit 92ce4c3 into console-rs:main Dec 30, 2021
@dabreegster dabreegster deleted the human_count branch December 30, 2021 23:01
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

2 participants