Skip to content

Commit d85e455

Browse files
committed
Fix Default impl
1 parent 4e9bedc commit d85e455

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/c_string.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use core::{
1313
/// A fixed capacity [`CString`](https://doc.rust-lang.org/std/ffi/struct.CString.html).
1414
///
1515
/// It stores up to `N - 1` non-nul characters with a trailing nul terminator.
16-
#[derive(Clone, Default, Hash)]
16+
#[derive(Clone, Hash)]
1717
pub struct CString<const N: usize> {
1818
inner: Vec<u8, N>,
1919
}
@@ -273,6 +273,13 @@ impl<const N: usize> CString<N> {
273273
}
274274
}
275275

276+
impl<const N: usize> Default for CString<N> {
277+
#[inline]
278+
fn default() -> Self {
279+
Self::new()
280+
}
281+
}
282+
276283
impl<const N: usize> Borrow<CStr> for CString<N> {
277284
#[inline]
278285
fn borrow(&self) -> &CStr {
@@ -445,6 +452,10 @@ mod tests {
445452
Some(INITIAL_BYTES.len() + 5)
446453
);
447454
}
455+
#[test]
456+
fn default() {
457+
assert_eq!(CString::<1>::default().as_c_str(), <&CStr>::default());
458+
}
448459

449460
#[test]
450461
fn deref() {

0 commit comments

Comments
 (0)