Skip to content

Commit

Permalink
Fix implementation of Default and add short test
Browse files Browse the repository at this point in the history
Due to the cherry pick the previous commit was shuffled and its
dependencies were not fulfilled.
  • Loading branch information
Thomas Bahn committed May 2, 2016
1 parent dbd3304 commit 082c577
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/ascii_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ impl PartialOrd<AsciiString> for AsciiStr {
}
*/

impl Default for &'static AsciiStr {
fn default() -> &'static AsciiStr {
unsafe { mem::transmute("") }
}
}

impl ToOwned for AsciiStr {
type Owned = AsciiString;

Expand Down Expand Up @@ -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) }
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 082c577

Please sign in to comment.