From 082c57764427006f741bcea4b4c33773c29f6691 Mon Sep 17 00:00:00 2001 From: Thomas Bahn Date: Mon, 2 May 2016 13:11:49 +0200 Subject: [PATCH] Fix implementation of Default and add short test Due to the cherry pick the previous commit was shuffled and its dependencies were not fulfilled. --- src/ascii_str.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/ascii_str.rs b/src/ascii_str.rs index b06fd40..56677e7 100644 --- a/src/ascii_str.rs +++ b/src/ascii_str.rs @@ -178,6 +178,12 @@ impl PartialOrd for AsciiStr { } */ +impl Default for &'static AsciiStr { + fn default() -> &'static AsciiStr { + unsafe { mem::transmute("") } + } +} + impl ToOwned for AsciiStr { type Owned = AsciiString; @@ -207,11 +213,6 @@ impl AsMut<[Ascii]> for AsciiStr { } } -impl Default for &'static AsciiStr { - fn default() -> &'static AsciiStr { - unsafe{ "".into_ascii_unchecked() } - } -} impl<'a> From<&'a[Ascii]> for &'a AsciiStr { fn from(slice: &[Ascii]) -> &AsciiStr { unsafe{ mem::transmute(slice) } @@ -346,6 +347,12 @@ mod tests { use AsciiCast; use super::AsciiStr; + #[test] + fn default() { + let default: &'static AsciiStr = Default::default(); + assert!(default.is_empty()); + } + #[test] fn as_str() { let b = &[40_u8, 32, 59];