Skip to content

Commit 6dbfd72

Browse files
authored
Merge pull request #12 from clarcharr/master
Implement Display for Recompositions, Decompositions
2 parents 414a14f + 2d59884 commit 6dbfd72

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/decompose.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use std::fmt::{self, Write};
1112

1213
// Helper functions used for Unicode normalization
1314
fn canonical_sort(comb: &mut [(char, u8)]) {
@@ -133,3 +134,12 @@ impl<I: Iterator<Item=char>> Iterator for Decompositions<I> {
133134
(lower, None)
134135
}
135136
}
137+
138+
impl<I: Iterator<Item=char> + Clone> fmt::Display for Decompositions<I> {
139+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
140+
for c in self.clone() {
141+
f.write_char(c)?;
142+
}
143+
Ok(())
144+
}
145+
}

src/recompose.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
use std::collections::VecDeque;
12+
use std::fmt::{self, Write};
1213
use decompose::Decompositions;
1314

1415
#[derive(Clone)]
@@ -135,3 +136,12 @@ impl<I: Iterator<Item=char>> Iterator for Recompositions<I> {
135136
}
136137
}
137138
}
139+
140+
impl<I: Iterator<Item=char> + Clone> fmt::Display for Recompositions<I> {
141+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
142+
for c in self.clone() {
143+
f.write_char(c)?;
144+
}
145+
Ok(())
146+
}
147+
}

src/test.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ use UnicodeNormalization;
1414
fn test_nfd() {
1515
macro_rules! t {
1616
($input: expr, $expected: expr) => {
17-
assert_eq!($input.nfd().collect::<String>(), $expected);
18-
// A dummy iterator that is not std::str::Chars directly:
17+
assert_eq!($input.nfd().to_string(), $expected);
18+
// A dummy iterator that is not std::str::Chars directly;
19+
// note that `id_func` is used to ensure `Clone` implementation
1920
assert_eq!($input.chars().map(|c| c).nfd().collect::<String>(), $expected);
2021
}
2122
}
@@ -35,7 +36,7 @@ fn test_nfd() {
3536
fn test_nfkd() {
3637
macro_rules! t {
3738
($input: expr, $expected: expr) => {
38-
assert_eq!($input.nfkd().collect::<String>(), $expected);
39+
assert_eq!($input.nfkd().to_string(), $expected);
3940
}
4041
}
4142
t!("abc", "abc");
@@ -54,7 +55,7 @@ fn test_nfkd() {
5455
fn test_nfc() {
5556
macro_rules! t {
5657
($input: expr, $expected: expr) => {
57-
assert_eq!($input.nfc().collect::<String>(), $expected);
58+
assert_eq!($input.nfc().to_string(), $expected);
5859
}
5960
}
6061
t!("abc", "abc");
@@ -74,7 +75,7 @@ fn test_nfc() {
7475
fn test_nfkc() {
7576
macro_rules! t {
7677
($input: expr, $expected: expr) => {
77-
assert_eq!($input.nfkc().collect::<String>(), $expected);
78+
assert_eq!($input.nfkc().to_string(), $expected);
7879
}
7980
}
8081
t!("abc", "abc");

0 commit comments

Comments
 (0)