pub fn width(text: &str) -> u64
Expand description

Return the number of columns required to display the text string in a monospace font as a sequence of extended grapheme clusters.

Overflow is not realistically possible in this function with u64 since each operation takes ~20 nanoseconds to complete (~500 years of continuous operation to overflow). In terms of memory, an 18 exabyte string would need to be parsed to overflow.

Examples

use unicode_display_width::width;

assert_eq!(width("👨‍👩‍👧‍👧"), 2);
assert_eq!(width("слава україні"), 13); // Glory to Ukraine in Ukrainian
assert_eq!(width("ݓ΅ɓԶѥƘҕ࠹ɇঐԢظٰ"), 12); // randomly generated Unicode