Skip to content

Commit 3693f0b

Browse files
committed
value: iterator of Compatible now returns &[u8]
Signed-off-by: Zhouqi Jiang <luojia@hust.edu.cn>
1 parent 9aa374e commit 3693f0b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/value/compatible.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<'de: 'a, 'a> Deserialize<'de> for Compatible<'a> {
3333
where
3434
E: serde::de::Error,
3535
{
36-
// TODO utf-8 check
36+
// no UTF-8 checks
3737
Ok(Compatible { data: v })
3838
}
3939
}
@@ -43,7 +43,14 @@ impl<'de: 'a, 'a> Deserialize<'de> for Compatible<'a> {
4343

4444
impl fmt::Debug for Compatible<'_> {
4545
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46-
f.debug_list().entries(self.iter()).finish()
46+
let mut list = f.debug_list();
47+
for slice in self.iter() {
48+
match core::str::from_utf8(slice) {
49+
Ok(string) => list.entry(&string),
50+
Err(_error) => list.entry(&slice),
51+
};
52+
}
53+
list.finish()
4754
}
4855
}
4956

@@ -52,7 +59,7 @@ pub struct Iter<'a> {
5259
}
5360

5461
impl<'a> Iterator for Iter<'a> {
55-
type Item = &'a str;
62+
type Item = &'a [u8];
5663

5764
fn next(&mut self) -> Option<Self::Item> {
5865
if self.remaining.len() == 0 {
@@ -70,6 +77,6 @@ impl<'a> Iterator for Iter<'a> {
7077
// skip '\0'
7178
self.remaining = &rest[1..];
7279
}
73-
Some(core::str::from_utf8(ans).unwrap())
80+
Some(ans)
7481
}
7582
}

0 commit comments

Comments
 (0)