segments

Macro segments 

Source
macro_rules! segments {
    () => { ... };
    (DOT) => { ... };
    ($($($a1:literal)?$($a2:ident)? $(- $($b1:literal)?$($b2:ident)?)?),+) => { ... };
    (~ $($($a1:literal)?$($a2:ident)? $(- $($b1:literal)?$($b2:ident)?)?),+) => { ... };
    ($($($a1:literal)?$($a2:ident)? $(- $($b1:literal)?$($b2:ident)?)?,)+) => { ... };
}
Expand description

Generates a Segments initialization from Seg values. The macro only accepts literals, either characters or integers, along with a few identifiers:

  • DOT matches all UTF-8 characters
  • MIN = 0
  • LOW_MAX = 0xd7ff
  • GAP_MIN = 0xd800 (GAP_MIN - GAP_MAX are forbidden UTF-8 codepoint values)
  • GAP_MAX = 0xdfff
  • HIGH_MIN = 0xe000
  • MAX = 0x10ffff

Integer values are UTF-8 codepoint values, not the 1-4 byte representation.

ยงExample

assert_eq!(segments!('a', '0'-'9'), Segments::from([Seg('a' as u32, 'a' as u32), Seg('0' as u32, '9' as u32)]));
assert_eq!(segments!(DOT), Segments::dot());
assert_eq!(segments!(~ '1'-'8'), segments![MIN-'0', '9'-LOW_MAX, HIGH_MIN-MAX]);