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

Put example in Readme #22

Open
stefnotch opened this issue Apr 11, 2023 · 3 comments · May be fixed by #23
Open

Put example in Readme #22

stefnotch opened this issue Apr 11, 2023 · 3 comments · May be fixed by #23

Comments

@stefnotch
Copy link

stefnotch commented Apr 11, 2023

The comparison of performance part has me convinced.

Now how do I use this lovely crate? Right, I head over to docs.rs and read through the performance comparison again.

Ooooh, down there are the two functions.

Would it be possible to have a minimal example at the top of the readme that showcases the really sleek API? Something like

let is_identifier_start = is_xid_start('c');
let is_identifier_continue = is_xid_continue('a');
let is_identifier_continue = is_xid_continue('t');

Also, thank you very much for all your awesome work on those lovely Rust projects!

@dtolnay
Copy link
Owner

dtolnay commented Apr 11, 2023

I don't think the code you've suggested would add any value in making sense of the API.

@dtolnay dtolnay closed this as completed Apr 11, 2023
@stefnotch
Copy link
Author

stefnotch commented Apr 11, 2023

IMO it'd still be worthwhile to mention which functions the API actually provides, without having to search quite as much.

@stefnotch
Copy link
Author

stefnotch commented Apr 11, 2023

But yes, the example isn't that well chosen. Here'd be a possibly more useful example. (Untested though)

fn is_identifier(value: &str) {
  let mut chars = value.chars();
  chars.next().filter(|c| is_xid_start(*c)).is_some() && chars.all(|c| is_xid_continue(c))
}


is_identifier("cat1"); // returns true
is_identifier("42"); // returns false

@dtolnay dtolnay reopened this Apr 11, 2023
@kangalio kangalio linked a pull request May 21, 2023 that will close this issue
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 a pull request may close this issue.

2 participants