unicode-rs / unicode-segmentation

Grapheme Cluster and Word boundaries according to UAX#29 rules
https://unicode-rs.github.io/unicode-segmentation
Other
565 stars 57 forks source link

Provide a simple macro for the common use case of splitting by grapheme into a vector #106

Closed tgross35 closed 2 years ago

tgross35 commented 2 years ago

It's a fairly common task (in my use at least) that's kind of clunky to do. The macro is small and could either be in the crates or the docs, or even just here!

#[macro_export]
macro_rules! graph_vec {
    ($ex:expr) => {
        $ex.graphemes(true).collect::<Vec<&str>>()
    };
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=0715ba0dd9359305756bc265b092dc1a

Manishearth commented 2 years ago

I don't find this kind of API to be typical Rust design: if it can be done with combinators it probably will be.

Furthermore I don't actually think this particular usage is that common, it really depends on what you're trying to do.