Skip to content

Commit 738e3b6

Browse files
committed
0.6.2 - add traits to NulTermStr
1 parent 4cbb47e commit 738e3b6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/arena.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::mem::size_of;
55
use std::ops::Deref;
66
use std::cell::Cell;
77
use std::borrow::Cow;
8+
use std::fmt;
89

910
const ARENA_BLOCK: usize = 64 * 1024;
1011

@@ -72,8 +73,21 @@ impl<'arena, T: 'arena> From<&'arena mut T> for Uninitialized<'arena, T> {
7273

7374
/// A wrapper around a `str` slice that has an extra `0` byte allocated following
7475
/// its contents.
76+
#[derive(Clone, Copy, PartialEq)]
7577
pub struct NulTermStr<'arena>(&'arena str);
7678

79+
impl<'arena> fmt::Debug for NulTermStr<'arena> {
80+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
81+
fmt::Debug::fmt(self.0, f)
82+
}
83+
}
84+
85+
impl<'arena> fmt::Display for NulTermStr<'arena> {
86+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
87+
fmt::Display::fmt(self.0, f)
88+
}
89+
}
90+
7791
impl<'arena> NulTermStr<'arena> {
7892
/// Read byte at a given `index`. This does not check for length boundaries,
7993
/// but is guaranteed to return `0` for `index` equal to the length.
@@ -437,5 +451,7 @@ mod test {
437451
b'a', b'b', b'c', b'd', b'e', b'f', b'g', b'h', b'i', b'j', b'k', 0
438452
]
439453
);
454+
455+
assert_eq!(nts.to_string(), "abcdefghijk");
440456
}
441457
}

0 commit comments

Comments
 (0)