Put example in Readme
stefnotch opened this issue · comments
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!
I don't think the code you've suggested would add any value in making sense of the API.
IMO it'd still be worthwhile to mention which functions the API actually provides, without having to search quite as much.
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