[std::path] Rename .container_as_str_opt() to .container_as_str(), drop the old .container_as_str() behavior

This commit is contained in:
Simon Sapin 2013-12-23 17:15:53 +01:00
parent e75d0a9b7e
commit 46b01647ba
2 changed files with 11 additions and 40 deletions

View file

@ -426,7 +426,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
let t: Option<T> = None;
if BytesContainer::is_str(t) {
for p in paths.iter() {
self.push(p.container_as_str())
self.push(p.container_as_str().unwrap())
}
} else {
for p in paths.iter() {
@ -499,18 +499,9 @@ pub trait BytesContainer {
fn container_into_owned_bytes(self) -> ~[u8] {
self.container_as_bytes().to_owned()
}
/// Returns the receiver interpreted as a utf-8 string
///
/// # Failure
///
/// Raises `str::null_byte` if not utf-8
#[inline]
fn container_as_str<'a>(&'a self) -> &'a str {
str::from_utf8(self.container_as_bytes())
}
/// Returns the receiver interpreted as a utf-8 string, if possible
#[inline]
fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> {
fn container_as_str<'a>(&'a self) -> Option<&'a str> {
str::from_utf8_opt(self.container_as_bytes())
}
/// Returns whether .container_as_str() is guaranteed to not fail
@ -589,11 +580,7 @@ impl<'a> BytesContainer for &'a str {
self.as_bytes()
}
#[inline]
fn container_as_str<'a>(&'a self) -> &'a str {
*self
}
#[inline]
fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> {
fn container_as_str<'a>(&'a self) -> Option<&'a str> {
Some(*self)
}
#[inline]
@ -610,11 +597,7 @@ impl BytesContainer for ~str {
self.into_bytes()
}
#[inline]
fn container_as_str<'a>(&'a self) -> &'a str {
self.as_slice()
}
#[inline]
fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> {
fn container_as_str<'a>(&'a self) -> Option<&'a str> {
Some(self.as_slice())
}
#[inline]
@ -627,11 +610,7 @@ impl BytesContainer for @str {
self.as_bytes()
}
#[inline]
fn container_as_str<'a>(&'a self) -> &'a str {
self.as_slice()
}
#[inline]
fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> {
fn container_as_str<'a>(&'a self) -> Option<&'a str> {
Some(self.as_slice())
}
#[inline]

View file

@ -129,11 +129,7 @@ impl BytesContainer for Path {
self.into_vec()
}
#[inline]
fn container_as_str<'a>(&'a self) -> &'a str {
self.as_str().unwrap()
}
#[inline]
fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> {
fn container_as_str<'a>(&'a self) -> Option<&'a str> {
self.as_str()
}
#[inline]
@ -146,11 +142,7 @@ impl<'a> BytesContainer for &'a Path {
self.as_vec()
}
#[inline]
fn container_as_str<'a>(&'a self) -> &'a str {
self.as_str().unwrap()
}
#[inline]
fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> {
fn container_as_str<'a>(&'a self) -> Option<&'a str> {
self.as_str()
}
#[inline]
@ -165,7 +157,7 @@ impl GenericPathUnsafe for Path {
/// Raises the `str::not_utf8` condition if not valid UTF-8.
#[inline]
unsafe fn new_unchecked<T: BytesContainer>(path: T) -> Path {
let (prefix, path) = Path::normalize_(path.container_as_str());
let (prefix, path) = Path::normalize_(path.container_as_str().unwrap());
assert!(!path.is_empty());
let mut ret = Path{ repr: path, prefix: prefix, sepidx: None };
ret.update_sepidx();
@ -178,7 +170,7 @@ impl GenericPathUnsafe for Path {
///
/// Raises the `str::not_utf8` condition if not valid UTF-8.
unsafe fn set_filename_unchecked<T: BytesContainer>(&mut self, filename: T) {
let filename = filename.container_as_str();
let filename = filename.container_as_str().unwrap();
match self.sepidx_or_prefix_len() {
None if ".." == self.repr => {
let mut s = str::with_capacity(3 + filename.len());
@ -224,7 +216,7 @@ impl GenericPathUnsafe for Path {
/// the new path is relative to. Otherwise, the new path will be treated
/// as if it were absolute and will replace the receiver outright.
unsafe fn push_unchecked<T: BytesContainer>(&mut self, path: T) {
let path = path.container_as_str();
let path = path.container_as_str().unwrap();
fn is_vol_abs(path: &str, prefix: Option<PathPrefix>) -> bool {
// assume prefix is Some(DiskPrefix)
let rest = path.slice_from(prefix_len(prefix));
@ -311,7 +303,7 @@ impl GenericPathUnsafe for Path {
impl GenericPath for Path {
#[inline]
fn new_opt<T: BytesContainer>(path: T) -> Option<Path> {
let s = path.container_as_str_opt();
let s = path.container_as_str();
match s {
None => None,
Some(s) => {