diff options
| author | Simon Sapin <simon.sapin@exyr.org> | 2013-12-23 17:15:53 +0100 |
|---|---|---|
| committer | Simon Sapin <simon.sapin@exyr.org> | 2014-01-21 15:48:47 -0800 |
| commit | 46b01647ba14f1d66d5af2cd70bea400d3ca4df3 (patch) | |
| tree | 4f8be1e9263c737ea2e19c5c918f93178ff4b094 /src/libstd | |
| parent | e75d0a9b7e45f007bd7771c46d0d34b3ab6e9607 (diff) | |
| download | rust-46b01647ba14f1d66d5af2cd70bea400d3ca4df3.tar.gz rust-46b01647ba14f1d66d5af2cd70bea400d3ca4df3.zip | |
[std::path] Rename .container_as_str_opt() to .container_as_str(), drop the old .container_as_str() behavior
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/path/mod.rs | 31 | ||||
| -rw-r--r-- | src/libstd/path/windows.rs | 20 |
2 files changed, 11 insertions, 40 deletions
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<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] 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<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) => { |
