@@ -55,21 +55,15 @@ pub use tables::UNICODE_VERSION;
55
55
mod tables;
56
56
57
57
/// Methods for determining displayed width of Unicode characters.
58
- #[ allow( missing_docs) ]
59
58
pub trait UnicodeWidthChar {
60
- fn width ( self ) -> Option < usize > ;
61
- fn width_cjk ( self ) -> Option < usize > ;
62
- }
63
-
64
- impl UnicodeWidthChar for char {
65
59
/// Returns the character's displayed width in columns, or `None` if the
66
60
/// character is a control character other than `'\x00'`.
67
61
///
68
62
/// This function treats characters in the Ambiguous category according
69
63
/// to [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
70
64
/// as 1 column wide. This is consistent with the recommendations for non-CJK
71
65
/// contexts, or when the context cannot be reliably determined.
72
- fn width ( self ) -> Option < usize > { cw :: width ( self , false ) }
66
+ fn width ( self ) -> Option < usize > ;
73
67
74
68
/// Returns the character's displayed width in columns, or `None` if the
75
69
/// character is a control character other than `'\x00'`.
@@ -78,17 +72,17 @@ impl UnicodeWidthChar for char {
78
72
/// to [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
79
73
/// as 2 columns wide. This is consistent with the recommendations for
80
74
/// CJK contexts.
75
+ fn width_cjk ( self ) -> Option < usize > ;
76
+ }
77
+
78
+ impl UnicodeWidthChar for char {
79
+ fn width ( self ) -> Option < usize > { cw:: width ( self , false ) }
80
+
81
81
fn width_cjk ( self ) -> Option < usize > { cw:: width ( self , true ) }
82
82
}
83
83
84
84
/// Methods for determining displayed width of Unicode strings.
85
- #[ allow( missing_docs) ]
86
85
pub trait UnicodeWidthStr {
87
- fn width < ' a > ( & ' a self ) -> usize ;
88
- fn width_cjk < ' a > ( & ' a self ) -> usize ;
89
- }
90
-
91
- impl UnicodeWidthStr for str {
92
86
/// Returns the string's displayed width in columns.
93
87
///
94
88
/// Control characters are treated as having zero width.
@@ -97,9 +91,7 @@ impl UnicodeWidthStr for str {
97
91
/// to [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
98
92
/// as 1 column wide. This is consistent with the recommendations for
99
93
/// non-CJK contexts, or when the context cannot be reliably determined.
100
- fn width ( & self ) -> usize {
101
- self . chars ( ) . map ( |c| cw:: width ( c, false ) . unwrap_or ( 0 ) ) . sum ( )
102
- }
94
+ fn width < ' a > ( & ' a self ) -> usize ;
103
95
104
96
/// Returns the string's displayed width in columns.
105
97
///
@@ -109,6 +101,14 @@ impl UnicodeWidthStr for str {
109
101
/// to [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
110
102
/// as 2 column wide. This is consistent with the recommendations for
111
103
/// CJK contexts.
104
+ fn width_cjk < ' a > ( & ' a self ) -> usize ;
105
+ }
106
+
107
+ impl UnicodeWidthStr for str {
108
+ fn width ( & self ) -> usize {
109
+ self . chars ( ) . map ( |c| cw:: width ( c, false ) . unwrap_or ( 0 ) ) . sum ( )
110
+ }
111
+
112
112
fn width_cjk ( & self ) -> usize {
113
113
self . chars ( ) . map ( |c| cw:: width ( c, true ) . unwrap_or ( 0 ) ) . sum ( )
114
114
}
0 commit comments