Home > OS >  Range of unicode as array of vector
Range of unicode as array of vector

Time:05-26

I'm trying to get the unicodes from \u0300 to \u036f as an array or a vector in Rust.

I tried several things but those haven't worked yet.

CodePudding user response:

You can create a range of chars, and collect them into a Vec:

Vec::from_iter('\u{0300}'..='\u{036f}')

Playground.

Creating an array is a little more difficult, but also possible:

const LEN: usize = '\u{036f}' as usize - '\u{0300}' as usize;
let mut arr = ['\0'; LEN];
for (item, ch) in std::iter::zip(&mut arr, '\u{0300}'..='\u{036f}') {
    *item = ch;
}

Playground.

  • Related