}
}
+#[stable]
+impl<T: fmt::String> fmt::String for Arc<T> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fmt::String::fmt(&**self, f)
+ }
+}
+
#[stable]
impl<T: Default + Sync + Send> Default for Arc<T> {
#[stable]
}
}
+#[stable]
impl<T: ?Sized + fmt::String> fmt::String for Box<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::String::fmt(&**self, f)
}
}
+#[stable]
+impl<T: fmt::String> fmt::String for Rc<T> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fmt::String::fmt(&**self, f)
+ }
+}
+
/// A weak version of `Rc<T>`.
///
/// Weak references do not count when determining if the inner value should be dropped.
}
}
+#[stable]
impl fmt::String for FromUtf8Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::String::fmt(&self.error, f)
}
}
+#[stable]
impl fmt::String for FromUtf16Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::String::fmt("invalid utf-16: lone surrogate found", f)
}
}
-#[experimental = "waiting on fmt stabilization"]
+#[stable]
impl fmt::String for String {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::String::fmt(&**self, f)
assert_eq!(2u8.to_string(), "2");
assert_eq!(true.to_string(), "true");
assert_eq!(false.to_string(), "false");
- assert_eq!(().to_string(), "()");
assert_eq!(("hi".to_string()).to_string(), "hi");
}
#[test]
fn test_vectors() {
let x: Vec<int> = vec![];
- assert_eq!(x.to_string(), "[]");
- assert_eq!((vec![1i]).to_string(), "[1]");
- assert_eq!((vec![1i, 2, 3]).to_string(), "[1, 2, 3]");
- assert!((vec![vec![], vec![1i], vec![1i, 1]]).to_string() ==
- "[[], [1], [1, 1]]");
+ assert_eq!(format!("{:?}", x), "[]");
+ assert_eq!(format!("{:?}", vec![1i]), "[1i]");
+ assert_eq!(format!("{:?}", vec![1i, 2, 3]), "[1i, 2i, 3i]");
+ assert!(format!("{:?}", vec![vec![], vec![1i], vec![1i, 1]]) ==
+ "[[], [1i], [1i, 1i]]");
}
#[test]
}
}
-#[cfg(stage0)]
-#[experimental = "waiting on Show stability"]
-impl<T: fmt::Show> fmt::String for Vec<T> {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- fmt::String::fmt(self.as_slice(), f)
- }
-}
-
-#[cfg(not(stage0))]
-#[experimental = "waiting on Show stability"]
-impl<T: fmt::String> fmt::String for Vec<T> {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- fmt::String::fmt(self.as_slice(), f)
- }
-}
-
impl<'a> fmt::Writer for Vec<u8> {
fn write_str(&mut self, s: &str) -> fmt::Result {
self.push_all(s.as_bytes());
}
}
+#[stable]
impl<'a, T, B: ?Sized> fmt::String for Cow<'a, T, B> where
B: fmt::String + ToOwned<T>,
T: fmt::String,
}
}
+#[stable]
impl<'a> String for Arguments<'a> {
fn fmt(&self, fmt: &mut Formatter) -> Result {
write(fmt.buf, *self)
}
}
+#[stable]
impl String for bool {
fn fmt(&self, f: &mut Formatter) -> Result {
String::fmt(if *self { "true" } else { "false" }, f)
}
}
+#[stable]
impl String for str {
fn fmt(&self, f: &mut Formatter) -> Result {
f.pad(self)
}
}
+#[stable]
impl String for char {
fn fmt(&self, f: &mut Formatter) -> Result {
let mut utf8 = [0u8; 4];
}
}
+ #[stable]
impl String for $ty {
fn fmt(&self, fmt: &mut Formatter) -> Result {
use num::Float;
impl<T> Show for *const T {
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
}
-impl<T> String for *const T {
- fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
-}
impl<T> Show for *mut T {
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
}
-impl<T> String for *mut T {
- fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
-}
macro_rules! peel {
($name:ident, $($other:ident,)*) => (tuple! { $($other,)* })
}
}
-#[cfg(stage0)]
-impl<T: Show> String for [T] {
- fn fmt(&self, f: &mut Formatter) -> Result {
- if f.flags & (1 << (rt::FlagAlternate as uint)) == 0 {
- try!(write!(f, "["));
- }
- let mut is_first = true;
- for x in self.iter() {
- if is_first {
- is_first = false;
- } else {
- try!(write!(f, ", "));
- }
- try!(write!(f, "{}", *x))
- }
- if f.flags & (1 << (rt::FlagAlternate as uint)) == 0 {
- try!(write!(f, "]"));
- }
- Ok(())
- }
-}
-#[cfg(not(stage0))]
-impl<T: String> String for [T] {
- fn fmt(&self, f: &mut Formatter) -> Result {
- if f.flags & (1 << (rt::FlagAlternate as uint)) == 0 {
- try!(write!(f, "["));
- }
- let mut is_first = true;
- for x in self.iter() {
- if is_first {
- is_first = false;
- } else {
- try!(write!(f, ", "));
- }
- try!(write!(f, "{}", *x))
- }
- if f.flags & (1 << (rt::FlagAlternate as uint)) == 0 {
- try!(write!(f, "]"));
- }
- Ok(())
- }
-}
-
impl Show for () {
fn fmt(&self, f: &mut Formatter) -> Result {
f.pad("()")
}
}
-impl String for () {
- fn fmt(&self, f: &mut Formatter) -> Result {
- f.pad("()")
- }
-}
-
impl<T: Copy + Show> Show for Cell<T> {
fn fmt(&self, f: &mut Formatter) -> Result {
write!(f, "Cell {{ value: {:?} }}", self.get())
}
}
+#[stable]
impl String for Utf8Error {
fn fmt(&self, f: &mut Formatter) -> Result {
match *self {
use self::Option::*;
+use clone::Clone;
use cmp::{Eq, Ord};
use default::Default;
-use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator};
+use fmt;
use iter::{ExactSizeIterator};
+use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator};
use mem;
-use result::Result;
+use ops::{Deref, FnOnce};
use result::Result::{Ok, Err};
-use slice;
+use result::Result;
use slice::AsSlice;
-use clone::Clone;
-use ops::{Deref, FnOnce};
+use slice;
// Note that this is not a lang item per se, but it has a hidden dependency on
// `Iterator`, which is one. The compiler assumes that the `next` method of
#[stable]
impl<T> Default for Option<T> {
- #[stable]
#[inline]
#[stable]
fn default() -> Option<T> { None }
pub struct WhereClause<'a>(pub &'a clean::Generics);
/// Wrapper struct for emitting type parameter bounds.
pub struct TyParamBounds<'a>(pub &'a [clean::TyParamBound]);
+/// Wrapper struct for emitting a comma-separated list of items
+pub struct CommaSep<'a, T: 'a>(pub &'a [T]);
impl VisSpace {
pub fn get(&self) -> Option<ast::Visibility> {
}
}
+impl<'a, T: fmt::String> fmt::String for CommaSep<'a, T> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ for (i, item) in self.0.iter().enumerate() {
+ if i != 0 { try!(write!(f, ", ")); }
+ try!(write!(f, "{}", item));
+ }
+ Ok(())
+ }
+}
+
//NOTE(stage0): remove impl after snapshot
#[cfg(stage0)]
impl<'a> fmt::Show for TyParamBounds<'a> {
lifetimes = if decl.lifetimes.len() == 0 {
"".to_string()
} else {
- format!("for <{:#}>", decl.lifetimes)
+ format!("for <{}>",
+ CommaSep(decl.lifetimes.as_slice()))
},
args = decl.decl.inputs,
arrow = decl.decl.output,
lifetimes = if decl.lifetimes.len() == 0 {
"".to_string()
} else {
- format!("for <{:#}>", decl.lifetimes)
+ format!("for <{}>",
+ CommaSep(decl.lifetimes.as_slice()))
},
args = decl.decl.inputs,
bounds = if decl.bounds.len() == 0 {
primitive_link(f, clean::PrimitiveTuple,
match typs.as_slice() {
[ref one] => format!("({},)", one),
- many => format!("({:#})", many)
+ many => format!("({})",
+ CommaSep(many.as_slice()))
}.as_slice())
}
clean::Vector(ref t) => {
impl fmt::Show for Path {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "Path {{ {} }}", self.display())
+ fmt::Show::fmt(&self.display(), f)
}
}
impl fmt::Show for Path {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "Path {{ {} }}", self.display())
+ fmt::Show::fmt(&self.display(), f)
}
}
impl<'a> Drop for defer<'a> {
fn drop(&mut self) {
unsafe {
- println!("{}", self.x);
+ println!("{:?}", self.x);
}
}
}
}
fn main() {
- println!("{}", read_lines_borrowed());
+ println!("{:?}", read_lines_borrowed());
}
assert_eq!((*arc_v)[2], 3);
- println!("{}", *arc_v);
+ println!("{:?}", *arc_v);
}
assert_eq!((*arc_v)[2], 3); //~ ERROR use of moved value: `arc_v`
- println!("{}", *arc_v); //~ ERROR use of moved value: `arc_v`
+ println!("{:?}", *arc_v); //~ ERROR use of moved value: `arc_v`
}
let foo = Foo { bar: [1u8, 2, 3, 4, 5], baz: 10i32 };
unsafe {
let oof: Oof<[u8; 5], i32> = mem::transmute(foo);
- println!("{} {}", &oof.rab[], oof.zab);
+ println!("{:?} {:?}", &oof.rab[], oof.zab);
}
}
let c : &[int] = &[2,2,2,2,3];
let cc : &[int] = &[2,2,2,2,2,2];
- println!("{}", a);
+ println!("{:?}", a);
assert!(a < b);
assert!(a <= b);
assert!(b >= a);
assert!(b > a);
- println!("{}", b);
+ println!("{:?}", b);
assert!(b < c);
assert!(b <= c);
assert!(c >= a);
assert!(c > a);
- println!("{}", c);
+ println!("{:?}", c);
assert!(a < cc);
assert!(a <= cc);
assert!(cc >= a);
assert!(cc > a);
- println!("{}", cc);
+ println!("{:?}", cc);
}
// can do with them just yet (to test the output)
fn test_print() {
print!("hi");
- print!("{}", vec!(0u8));
+ print!("{:?}", vec!(0u8));
println!("hello");
println!("this is a {}", "test");
println!("{foo}", foo="bar");
let ss: &&[int] = &s;
let sss: &&&[int] = &ss;
- println!("{}", &s[0..3]);
- println!("{}", &ss[3..]);
- println!("{}", &sss[2..4]);
+ println!("{:?}", &s[0..3]);
+ println!("{:?}", &ss[3..]);
+ println!("{:?}", &sss[2..4]);
}
pub fn main() {
for &v in V.iter() {
- println!("{}", v.vec);
+ println!("{:?}", v.vec);
}
}
print!("[");
for xi in x.iter() {
- print!("{}, ", &xi[]);
+ print!("{:?}, ", &xi[]);
}
println!("]");
- println!("{}", &y[]);
+ println!("{:?}", &y[]);
}
// except according to those terms.
pub fn main() {
- assert_eq!((vec!(0i, 1)).to_string(), "[0, 1]".to_string());
+ assert_eq!(format!("{:?}", vec!(0i, 1)), "[0i, 1i]".to_string());
let foo = vec!(3i, 4);
let bar: &[int] = &[4, 5];
- assert_eq!(foo.to_string(), "[3, 4]".to_string());
- assert_eq!(bar.to_string(), "[4, 5]".to_string());
+ assert_eq!(format!("{:?}", foo), "[3i, 4i]");
+ assert_eq!(format!("{:?}", bar), "[4i, 5i]");
}