Skip to content

Commit 46b0164

Browse files
committed
[std::path] Rename .container_as_str_opt() to .container_as_str(), drop the old .container_as_str() behavior
1 parent e75d0a9 commit 46b0164

File tree

2 files changed

+11
-40
lines changed

2 files changed

+11
-40
lines changed

src/libstd/path/mod.rs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
426426
let t: Option<T> = None;
427427
if BytesContainer::is_str(t) {
428428
for p in paths.iter() {
429-
self.push(p.container_as_str())
429+
self.push(p.container_as_str().unwrap())
430430
}
431431
} else {
432432
for p in paths.iter() {
@@ -499,18 +499,9 @@ pub trait BytesContainer {
499499
fn container_into_owned_bytes(self) -> ~[u8] {
500500
self.container_as_bytes().to_owned()
501501
}
502-
/// Returns the receiver interpreted as a utf-8 string
503-
///
504-
/// # Failure
505-
///
506-
/// Raises `str::null_byte` if not utf-8
507-
#[inline]
508-
fn container_as_str<'a>(&'a self) -> &'a str {
509-
str::from_utf8(self.container_as_bytes())
510-
}
511502
/// Returns the receiver interpreted as a utf-8 string, if possible
512503
#[inline]
513-
fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> {
504+
fn container_as_str<'a>(&'a self) -> Option<&'a str> {
514505
str::from_utf8_opt(self.container_as_bytes())
515506
}
516507
/// Returns whether .container_as_str() is guaranteed to not fail
@@ -589,11 +580,7 @@ impl<'a> BytesContainer for &'a str {
589580
self.as_bytes()
590581
}
591582
#[inline]
592-
fn container_as_str<'a>(&'a self) -> &'a str {
593-
*self
594-
}
595-
#[inline]
596-
fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> {
583+
fn container_as_str<'a>(&'a self) -> Option<&'a str> {
597584
Some(*self)
598585
}
599586
#[inline]
@@ -610,11 +597,7 @@ impl BytesContainer for ~str {
610597
self.into_bytes()
611598
}
612599
#[inline]
613-
fn container_as_str<'a>(&'a self) -> &'a str {
614-
self.as_slice()
615-
}
616-
#[inline]
617-
fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> {
600+
fn container_as_str<'a>(&'a self) -> Option<&'a str> {
618601
Some(self.as_slice())
619602
}
620603
#[inline]
@@ -627,11 +610,7 @@ impl BytesContainer for @str {
627610
self.as_bytes()
628611
}
629612
#[inline]
630-
fn container_as_str<'a>(&'a self) -> &'a str {
631-
self.as_slice()
632-
}
633-
#[inline]
634-
fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> {
613+
fn container_as_str<'a>(&'a self) -> Option<&'a str> {
635614
Some(self.as_slice())
636615
}
637616
#[inline]

src/libstd/path/windows.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,7 @@ impl BytesContainer for Path {
129129
self.into_vec()
130130
}
131131
#[inline]
132-
fn container_as_str<'a>(&'a self) -> &'a str {
133-
self.as_str().unwrap()
134-
}
135-
#[inline]
136-
fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> {
132+
fn container_as_str<'a>(&'a self) -> Option<&'a str> {
137133
self.as_str()
138134
}
139135
#[inline]
@@ -146,11 +142,7 @@ impl<'a> BytesContainer for &'a Path {
146142
self.as_vec()
147143
}
148144
#[inline]
149-
fn container_as_str<'a>(&'a self) -> &'a str {
150-
self.as_str().unwrap()
151-
}
152-
#[inline]
153-
fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> {
145+
fn container_as_str<'a>(&'a self) -> Option<&'a str> {
154146
self.as_str()
155147
}
156148
#[inline]
@@ -165,7 +157,7 @@ impl GenericPathUnsafe for Path {
165157
/// Raises the `str::not_utf8` condition if not valid UTF-8.
166158
#[inline]
167159
unsafe fn new_unchecked<T: BytesContainer>(path: T) -> Path {
168-
let (prefix, path) = Path::normalize_(path.container_as_str());
160+
let (prefix, path) = Path::normalize_(path.container_as_str().unwrap());
169161
assert!(!path.is_empty());
170162
let mut ret = Path{ repr: path, prefix: prefix, sepidx: None };
171163
ret.update_sepidx();
@@ -178,7 +170,7 @@ impl GenericPathUnsafe for Path {
178170
///
179171
/// Raises the `str::not_utf8` condition if not valid UTF-8.
180172
unsafe fn set_filename_unchecked<T: BytesContainer>(&mut self, filename: T) {
181-
let filename = filename.container_as_str();
173+
let filename = filename.container_as_str().unwrap();
182174
match self.sepidx_or_prefix_len() {
183175
None if ".." == self.repr => {
184176
let mut s = str::with_capacity(3 + filename.len());
@@ -224,7 +216,7 @@ impl GenericPathUnsafe for Path {
224216
/// the new path is relative to. Otherwise, the new path will be treated
225217
/// as if it were absolute and will replace the receiver outright.
226218
unsafe fn push_unchecked<T: BytesContainer>(&mut self, path: T) {
227-
let path = path.container_as_str();
219+
let path = path.container_as_str().unwrap();
228220
fn is_vol_abs(path: &str, prefix: Option<PathPrefix>) -> bool {
229221
// assume prefix is Some(DiskPrefix)
230222
let rest = path.slice_from(prefix_len(prefix));
@@ -311,7 +303,7 @@ impl GenericPathUnsafe for Path {
311303
impl GenericPath for Path {
312304
#[inline]
313305
fn new_opt<T: BytesContainer>(path: T) -> Option<Path> {
314-
let s = path.container_as_str_opt();
306+
let s = path.container_as_str();
315307
match s {
316308
None => None,
317309
Some(s) => {

0 commit comments

Comments
 (0)