From 46b01647ba14f1d66d5af2cd70bea400d3ca4df3 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 23 Dec 2013 17:15:53 +0100 Subject: [std::path] Rename .container_as_str_opt() to .container_as_str(), drop the old .container_as_str() behavior --- src/libstd/path/mod.rs | 31 +++++-------------------------- src/libstd/path/windows.rs | 20 ++++++-------------- 2 files changed, 11 insertions(+), 40 deletions(-) (limited to 'src/libstd/path') diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 56df14ba763..b2de3cd9178 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -426,7 +426,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { let t: Option = 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] diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 89640add7d0..33fa84c7c49 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -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(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(&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(&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) -> 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(path: T) -> Option { - let s = path.container_as_str_opt(); + let s = path.container_as_str(); match s { None => None, Some(s) => { -- cgit 1.4.1-3-g733a5