Skip to content

Commit afabcb2

Browse files
committed
move docs to the Traits
1 parent 3df193d commit afabcb2

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/lib.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,15 @@ pub use tables::UNICODE_VERSION;
5555
mod tables;
5656

5757
/// Methods for determining displayed width of Unicode characters.
58-
#[allow(missing_docs)]
5958
pub trait UnicodeWidthChar {
60-
fn width(self) -> Option<usize>;
61-
fn width_cjk(self) -> Option<usize>;
62-
}
63-
64-
impl UnicodeWidthChar for char {
6559
/// Returns the character's displayed width in columns, or `None` if the
6660
/// character is a control character other than `'\x00'`.
6761
///
6862
/// This function treats characters in the Ambiguous category according
6963
/// to [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
7064
/// as 1 column wide. This is consistent with the recommendations for non-CJK
7165
/// 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>;
7367

7468
/// Returns the character's displayed width in columns, or `None` if the
7569
/// character is a control character other than `'\x00'`.
@@ -78,17 +72,17 @@ impl UnicodeWidthChar for char {
7872
/// to [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
7973
/// as 2 columns wide. This is consistent with the recommendations for
8074
/// 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+
8181
fn width_cjk(self) -> Option<usize> { cw::width(self, true) }
8282
}
8383

8484
/// Methods for determining displayed width of Unicode strings.
85-
#[allow(missing_docs)]
8685
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 {
9286
/// Returns the string's displayed width in columns.
9387
///
9488
/// Control characters are treated as having zero width.
@@ -97,9 +91,7 @@ impl UnicodeWidthStr for str {
9791
/// to [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
9892
/// as 1 column wide. This is consistent with the recommendations for
9993
/// 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;
10395

10496
/// Returns the string's displayed width in columns.
10597
///
@@ -109,6 +101,14 @@ impl UnicodeWidthStr for str {
109101
/// to [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
110102
/// as 2 column wide. This is consistent with the recommendations for
111103
/// 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+
112112
fn width_cjk(&self) -> usize {
113113
self.chars().map(|c| cw::width(c, true).unwrap_or(0)).sum()
114114
}

0 commit comments

Comments
 (0)