diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-02-19 18:56:33 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-02-23 20:51:56 -0800 |
| commit | b78b749810f4ed53e8287adfb284f9f32f16b73c (patch) | |
| tree | 0894e97a61d0ab09dd42d73202aeefca175463eb /src/libstd/path | |
| parent | 7cc6b5e0a3a2038d66301906f76cdb778304a3bd (diff) | |
| download | rust-b78b749810f4ed53e8287adfb284f9f32f16b73c.tar.gz rust-b78b749810f4ed53e8287adfb284f9f32f16b73c.zip | |
Remove all ToStr impls, add Show impls
This commit changes the ToStr trait to:
impl<T: fmt::Show> ToStr for T {
fn to_str(&self) -> ~str { format!("{}", *self) }
}
The ToStr trait has been on the chopping block for quite awhile now, and this is
the final nail in its coffin. The trait and the corresponding method are not
being removed as part of this commit, but rather any implementations of the
`ToStr` trait are being forbidden because of the generic impl. The new way to
get the `to_str()` method to work is to implement `fmt::Show`.
Formatting into a `&mut Writer` (as `format!` does) is much more efficient than
`ToStr` when building up large strings. The `ToStr` trait forces many
intermediate allocations to be made while the `fmt::Show` trait allows
incremental buildup in the same heap allocated buffer. Additionally, the
`fmt::Show` trait is much more extensible in terms of interoperation with other
`Writer` instances and in more situations. By design the `ToStr` trait requires
at least one allocation whereas the `fmt::Show` trait does not require any
allocations.
Closes #8242
Closes #9806
Diffstat (limited to 'src/libstd/path')
| -rw-r--r-- | src/libstd/path/mod.rs | 11 |
1 files changed, 0 insertions, 11 deletions
diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 13496033fd0..09124f63361 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -71,7 +71,6 @@ use iter::Iterator; use option::{Option, None, Some}; use str; use str::{MaybeOwned, OwnedStr, Str, StrSlice, from_utf8_lossy}; -use to_str::ToStr; use vec; use vec::{CloneableVector, OwnedCloneableVector, OwnedVector, Vector}; use vec::{ImmutableEqVector, ImmutableVector}; @@ -499,16 +498,6 @@ impl<'a, P: GenericPath> fmt::Show for Display<'a, P> { } } -impl<'a, P: GenericPath> ToStr for Display<'a, P> { - /// Returns the path as a string - /// - /// If the path is not UTF-8, invalid sequences with be replaced with the - /// unicode replacement char. This involves allocation. - fn to_str(&self) -> ~str { - self.as_maybe_owned().into_owned() - } -} - impl<'a, P: GenericPath> Display<'a, P> { /// Returns the path as a possibly-owned string. /// |
