diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-04-30 23:06:36 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-05-07 08:16:14 -0700 |
| commit | 9bae6ec828fdc7f87838ee008cccef90e31b9f84 (patch) | |
| tree | 97ae34844c9949ff5a49a6b99ff70dd2f0cbf6c0 /src/libstd/fmt | |
| parent | 544d90940166a9a83194801437dd37c0b1872c86 (diff) | |
| download | rust-9bae6ec828fdc7f87838ee008cccef90e31b9f84.tar.gz rust-9bae6ec828fdc7f87838ee008cccef90e31b9f84.zip | |
core: Inherit possible string functionality
This moves as much allocation as possible from teh std::str module into core::str. This includes essentially all non-allocating functionality, mostly iterators and slicing and such. This primarily splits the Str trait into only having the as_slice() method, adding a new StrAllocating trait to std::str which contains the relevant new allocation methods. This is a breaking change if any of the methods of "trait Str" were overriden. The old functionality can be restored by implementing both the Str and StrAllocating traits. [breaking-change]
Diffstat (limited to 'src/libstd/fmt')
| -rw-r--r-- | src/libstd/fmt/mod.rs | 21 | ||||
| -rw-r--r-- | src/libstd/fmt/num.rs | 2 |
2 files changed, 19 insertions, 4 deletions
diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index c80177b4644..9f683e45678 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -493,11 +493,11 @@ use io; use iter; use iter::{Iterator, range}; use num::Signed; -use option::{Option,Some,None}; +use option::{Option, Some, None}; use owned::Box; use repr; -use result::{Ok, Err}; -use str::StrSlice; +use result::{Ok, Err, ResultUnwrap}; +use str::{StrSlice, StrAllocating, UTF16Item, ScalarValue, LoneSurrogate}; use str; use slice::{Vector, ImmutableVector}; use slice; @@ -1359,5 +1359,20 @@ impl Show for cmp::Ordering { } } +impl<T: Copy + Show> Show for Cell<T> { + fn fmt(&self, f: &mut Formatter) -> Result { + write!(f.buf, r"Cell \{ value: {} \}", self.get()) + } +} + +impl Show for UTF16Item { + fn fmt(&self, f: &mut Formatter) -> Result { + match *self { + ScalarValue(c) => write!(f.buf, "ScalarValue({})", c), + LoneSurrogate(u) => write!(f.buf, "LoneSurrogate({})", u), + } + } +} + // If you expected tests to be here, look instead at the run-pass/ifmt.rs test, // it's a lot easier than creating all of the rt::Piece structures here. diff --git a/src/libstd/fmt/num.rs b/src/libstd/fmt/num.rs index 2032a2a6b58..12adcee2f0f 100644 --- a/src/libstd/fmt/num.rs +++ b/src/libstd/fmt/num.rs @@ -194,7 +194,7 @@ mod tests { use fmt::radix; use super::{Binary, Octal, Decimal, LowerHex, UpperHex}; use super::{GenericRadix, Radix}; - use str::StrSlice; + use str::StrAllocating; #[test] fn test_radix_base() { |
