1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! Extension trait for ergonomic width measurement.
//!
//! This module defines [`RuneDisplayWidth`], a trait implemented for both `char` and `str`,
//! providing convenient methods like `.width()`, `.rune_width()`, and `.display_widths()`.
//!
//! These methods offer a unified interface for querying terminal display width,
//! automatically applying grapheme segmentation where appropriate.
//!
//! See also:
//! - [`display_width`](crate::grapheme::display_width)
//! - [`WidthPolicy`](crate::policy::WidthPolicy) for configurable strategies
/// Extension trait for measuring the display width of runes, graphemes, and strings.
///
/// This trait provides unified access to terminal display width calculations
/// for both `char` and `&str`. It supports:
///
/// - Single runes (`char`)
/// - Full Unicode strings with grapheme segmentation (`&str`)
///
/// All widths are measured in terminal columns, respecting East Asian widths,
/// emoji sequences, and control characters.
///
/// # Examples
///
/// ```rust
/// use runefix_core::RuneDisplayWidth;
///
/// assert_eq!('語'.rune_width(), 2);
/// assert_eq!("ä½ ðŸ‘‹a".display_widths(), vec![2, 2, 1]);
/// assert_eq!("Hi👋".display_width(), 4);
/// assert_eq!("👋".width(), 2);
/// ```