Skip to content

Commit 082c577

Browse files
author
Thomas Bahn
committed
Fix implementation of Default and add short test
Due to the cherry pick the previous commit was shuffled and its dependencies were not fulfilled.
1 parent dbd3304 commit 082c577

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/ascii_str.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ impl PartialOrd<AsciiString> for AsciiStr {
178178
}
179179
*/
180180

181+
impl Default for &'static AsciiStr {
182+
fn default() -> &'static AsciiStr {
183+
unsafe { mem::transmute("") }
184+
}
185+
}
186+
181187
impl ToOwned for AsciiStr {
182188
type Owned = AsciiString;
183189

@@ -207,11 +213,6 @@ impl AsMut<[Ascii]> for AsciiStr {
207213
}
208214
}
209215

210-
impl Default for &'static AsciiStr {
211-
fn default() -> &'static AsciiStr {
212-
unsafe{ "".into_ascii_unchecked() }
213-
}
214-
}
215216
impl<'a> From<&'a[Ascii]> for &'a AsciiStr {
216217
fn from(slice: &[Ascii]) -> &AsciiStr {
217218
unsafe{ mem::transmute(slice) }
@@ -346,6 +347,12 @@ mod tests {
346347
use AsciiCast;
347348
use super::AsciiStr;
348349

350+
#[test]
351+
fn default() {
352+
let default: &'static AsciiStr = Default::default();
353+
assert!(default.is_empty());
354+
}
355+
349356
#[test]
350357
fn as_str() {
351358
let b = &[40_u8, 32, 59];

0 commit comments

Comments
 (0)