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

I went a little bit ahead of myself... #22

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

I went a little bit ahead of myself... #22

wants to merge 22 commits into from

Conversation

ghost
Copy link

@ghost ghost commented May 28, 2019

... and thought I could make it a nice practice to write it as idiomatically as possible.
In the process, I changed a lot, but I believe to the better.

  • Error handling is now done consistently, except for a few .expect() calls that I didn't fell worth removing right now.
  • Patterns are validated ahead of time
  • Regexes are cached and not compiled once per check

I hope you find these changes useful, in any case it was fun writing some Rust again :).

pattern,
})
})
.collect::<Result<_, _>>()?,
Copy link
Author

Choose a reason for hiding this comment

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

This is one of the best tricks in the book. Collect into a Result<_, _>, which is useful if your iterators produces Result<T, _>. That way, if there is an error, you will get it into the top level. You get a pristine Vec<T>.

human-panic = "1.0.1"
lazy_static = "1.3.0"
Copy link

Choose a reason for hiding this comment

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

maybe you can use OnceCell instead of lazy_static I guess

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.

1 participant