Add str.rs.

This commit is contained in:
Ms2ger 2014-02-14 13:20:48 +01:00
parent 59184bf6e1
commit 951d35902c

View file

@ -0,0 +1,21 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
pub type DOMString = ~str;
pub fn null_str_as_empty(s: &Option<DOMString>) -> DOMString {
// We don't use map_default because it would allocate ~"" even for Some.
match *s {
Some(ref s) => s.clone(),
None => ~""
}
}
pub fn null_str_as_empty_ref<'a>(s: &'a Option<DOMString>) -> &'a str {
match *s {
Some(ref s) => s.as_slice(),
None => &'a ""
}
}