pub struct Escape<'a>(&'a str);
impl<'a> fmt::Show for Escape<'a> {
- fn fmt(s: &Escape<'a>, fmt: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
// Because the internet is always right, turns out there's not that many
// characters to escape: http://stackoverflow.com/questions/7381974
- let Escape(s) = *s;
+ let Escape(s) = *self;
let pile_o_bits = s.as_slice();
let mut last = 0;
for (i, ch) in s.bytes().enumerate() {
}
impl fmt::Show for clean::Generics {
- fn fmt(g: &clean::Generics, f: &mut fmt::Formatter) -> fmt::Result {
- if g.lifetimes.len() == 0 && g.type_params.len() == 0 { return Ok(()) }
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ if self.lifetimes.len() == 0 && self.type_params.len() == 0 { return Ok(()) }
if_ok!(f.buf.write("<".as_bytes()));
- for (i, life) in g.lifetimes.iter().enumerate() {
+ for (i, life) in self.lifetimes.iter().enumerate() {
if i > 0 {
if_ok!(f.buf.write(", ".as_bytes()));
}
if_ok!(write!(f.buf, "{}", *life));
}
- if g.type_params.len() > 0 {
- if g.lifetimes.len() > 0 {
+ if self.type_params.len() > 0 {
+ if self.lifetimes.len() > 0 {
if_ok!(f.buf.write(", ".as_bytes()));
}
- for (i, tp) in g.type_params.iter().enumerate() {
+ for (i, tp) in self.type_params.iter().enumerate() {
if i > 0 {
if_ok!(f.buf.write(", ".as_bytes()))
}
}
impl fmt::Show for clean::Lifetime {
- fn fmt(l: &clean::Lifetime, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if_ok!(f.buf.write("'".as_bytes()));
- if_ok!(f.buf.write(l.get_ref().as_bytes()));
+ if_ok!(f.buf.write(self.get_ref().as_bytes()));
Ok(())
}
}
impl fmt::Show for clean::TyParamBound {
- fn fmt(bound: &clean::TyParamBound, f: &mut fmt::Formatter) -> fmt::Result {
- match *bound {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
clean::RegionBound => {
f.buf.write("'static".as_bytes())
}
}
impl fmt::Show for clean::Path {
- fn fmt(path: &clean::Path, f: &mut fmt::Formatter) -> fmt::Result {
- if path.global {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ if self.global {
if_ok!(f.buf.write("::".as_bytes()))
}
- for (i, seg) in path.segments.iter().enumerate() {
+ for (i, seg) in self.segments.iter().enumerate() {
if i > 0 {
if_ok!(f.buf.write("::".as_bytes()))
}
}
impl fmt::Show for clean::Type {
- fn fmt(g: &clean::Type, f: &mut fmt::Formatter) -> fmt::Result {
- match *g {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
clean::TyParamBinder(id) | clean::Generic(id) => {
local_data::get(cache_key, |cache| {
let m = cache.unwrap().get();
}
impl fmt::Show for clean::FnDecl {
- fn fmt(d: &clean::FnDecl, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f.buf, "({args}){arrow, select, yes{ -> {ret}} other{}}",
- args = d.inputs,
- arrow = match d.output { clean::Unit => "no", _ => "yes" },
- ret = d.output)
+ args = self.inputs,
+ arrow = match self.output { clean::Unit => "no", _ => "yes" },
+ ret = self.output)
}
}
impl fmt::Show for ~[clean::Argument] {
- fn fmt(inputs: &~[clean::Argument], f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut args = ~"";
- for (i, input) in inputs.iter().enumerate() {
+ for (i, input) in self.iter().enumerate() {
if i > 0 { args.push_str(", "); }
if input.name.len() > 0 {
args.push_str(format!("{}: ", input.name));
}
impl<'a> fmt::Show for Method<'a> {
- fn fmt(m: &Method<'a>, f: &mut fmt::Formatter) -> fmt::Result {
- let Method(selfty, d) = *m;
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ let Method(selfty, d) = *self;
let mut args = ~"";
match *selfty {
clean::SelfStatic => {},
}
impl fmt::Show for VisSpace {
- fn fmt(v: &VisSpace, f: &mut fmt::Formatter) -> fmt::Result {
- match v.get() {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match self.get() {
Some(ast::Public) => write!(f.buf, "pub "),
Some(ast::Private) => write!(f.buf, "priv "),
Some(ast::Inherited) | None => Ok(())
}
impl fmt::Show for PuritySpace {
- fn fmt(p: &PuritySpace, f: &mut fmt::Formatter) -> fmt::Result {
- match p.get() {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match self.get() {
ast::UnsafeFn => write!(f.buf, "unsafe "),
ast::ExternFn => write!(f.buf, "extern "),
ast::ImpureFn => Ok(())
}
impl fmt::Show for clean::ViewPath {
- fn fmt(v: &clean::ViewPath, f: &mut fmt::Formatter) -> fmt::Result {
- match *v {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
clean::SimpleImport(ref name, ref src) => {
if *name == src.path.segments.last().unwrap().name {
write!(f.buf, "use {};", *src)
}
impl fmt::Show for clean::ImportSource {
- fn fmt(v: &clean::ImportSource, f: &mut fmt::Formatter) -> fmt::Result {
- match v.did {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match self.did {
// FIXME: shouldn't be restricted to just local imports
Some(did) if ast_util::is_local(did) => {
- resolved_path(f.buf, did.node, &v.path, true)
+ resolved_path(f.buf, did.node, &self.path, true)
}
_ => {
- for (i, seg) in v.path.segments.iter().enumerate() {
+ for (i, seg) in self.path.segments.iter().enumerate() {
if i > 0 {
if_ok!(write!(f.buf, "::"))
}
}
impl fmt::Show for clean::ViewListIdent {
- fn fmt(v: &clean::ViewListIdent, f: &mut fmt::Formatter) -> fmt::Result {
- match v.source {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match self.source {
// FIXME: shouldn't be limited to just local imports
Some(did) if ast_util::is_local(did) => {
let path = clean::Path {
global: false,
segments: ~[clean::PathSegment {
- name: v.name.clone(),
+ name: self.name.clone(),
lifetimes: ~[],
types: ~[],
}]
};
resolved_path(f.buf, did.node, &path, false)
}
- _ => write!(f.buf, "{}", v.name),
+ _ => write!(f.buf, "{}", self.name),
}
}
}
}
impl<'a> fmt::Show for Markdown<'a> {
- fn fmt(md: &Markdown<'a>, fmt: &mut fmt::Formatter) -> fmt::Result {
- let Markdown(md) = *md;
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ let Markdown(md) = *self;
// This is actually common enough to special-case
if md.len() == 0 { return Ok(()) }
render(fmt.buf, md.as_slice())
}
impl<'a> fmt::Show for Item<'a> {
- fn fmt(it: &Item<'a>, fmt: &mut fmt::Formatter) -> fmt::Result {
- match attr::find_stability(it.item.attrs.iter()) {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ match attr::find_stability(self.item.attrs.iter()) {
Some(ref stability) => {
if_ok!(write!(fmt.buf,
"<a class='stability {lvl}' title='{reason}'>{lvl}</a>",
None => {}
}
- if it.cx.include_sources {
+ if self.cx.include_sources {
let mut path = ~[];
- clean_srcpath(it.item.source.filename.as_bytes(), |component| {
+ clean_srcpath(self.item.source.filename.as_bytes(), |component| {
path.push(component.to_owned());
});
- let href = if it.item.source.loline == it.item.source.hiline {
- format!("{}", it.item.source.loline)
+ let href = if self.item.source.loline == self.item.source.hiline {
+ format!("{}", self.item.source.loline)
} else {
- format!("{}-{}", it.item.source.loline, it.item.source.hiline)
+ format!("{}-{}", self.item.source.loline, self.item.source.hiline)
};
if_ok!(write!(fmt.buf,
"<a class='source'
href='{root}src/{crate}/{path}.html\\#{href}'>\
[src]</a>",
- root = it.cx.root_path,
- crate = it.cx.layout.crate,
+ root = self.cx.root_path,
+ crate = self.cx.layout.crate,
path = path.connect("/"),
href = href));
}
// Write the breadcrumb trail header for the top
if_ok!(write!(fmt.buf, "<h1 class='fqn'>"));
- match it.item.inner {
+ match self.item.inner {
clean::ModuleItem(..) => if_ok!(write!(fmt.buf, "Module ")),
clean::FunctionItem(..) => if_ok!(write!(fmt.buf, "Function ")),
clean::TraitItem(..) => if_ok!(write!(fmt.buf, "Trait ")),
clean::EnumItem(..) => if_ok!(write!(fmt.buf, "Enum ")),
_ => {}
}
- let cur = it.cx.current.as_slice();
- let amt = if it.ismodule() { cur.len() - 1 } else { cur.len() };
+ let cur = self.cx.current.as_slice();
+ let amt = if self.ismodule() { cur.len() - 1 } else { cur.len() };
for (i, component) in cur.iter().enumerate().take(amt) {
let mut trail = ~"";
for _ in range(0, cur.len() - i - 1) {
trail, component.as_slice()));
}
if_ok!(write!(fmt.buf, "<a class='{}' href=''>{}</a></h1>",
- shortty(it.item), it.item.name.get_ref().as_slice()));
+ shortty(self.item), self.item.name.get_ref().as_slice()));
- match it.item.inner {
- clean::ModuleItem(ref m) => item_module(fmt.buf, it.cx,
- it.item, m.items),
+ match self.item.inner {
+ clean::ModuleItem(ref m) => item_module(fmt.buf, self.cx,
+ self.item, m.items),
clean::FunctionItem(ref f) | clean::ForeignFunctionItem(ref f) =>
- item_function(fmt.buf, it.item, f),
- clean::TraitItem(ref t) => item_trait(fmt.buf, it.item, t),
- clean::StructItem(ref s) => item_struct(fmt.buf, it.item, s),
- clean::EnumItem(ref e) => item_enum(fmt.buf, it.item, e),
- clean::TypedefItem(ref t) => item_typedef(fmt.buf, it.item, t),
+ item_function(fmt.buf, self.item, f),
+ clean::TraitItem(ref t) => item_trait(fmt.buf, self.item, t),
+ clean::StructItem(ref s) => item_struct(fmt.buf, self.item, s),
+ clean::EnumItem(ref e) => item_enum(fmt.buf, self.item, e),
+ clean::TypedefItem(ref t) => item_typedef(fmt.buf, self.item, t),
_ => Ok(())
}
}
clean::StaticItem(ref s) | clean::ForeignStaticItem(ref s) => {
struct Initializer<'a>(&'a str);
impl<'a> fmt::Show for Initializer<'a> {
- fn fmt(s: &Initializer<'a>,
- f: &mut fmt::Formatter) -> fmt::Result {
- let Initializer(s) = *s;
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ let Initializer(s) = *self;
if s.len() == 0 { return Ok(()); }
if_ok!(write!(f.buf, "<code> = </code>"));
let tag = if s.contains("\n") { "pre" } else { "code" };
}
impl<'a> fmt::Show for Sidebar<'a> {
- fn fmt(s: &Sidebar<'a>, fmt: &mut fmt::Formatter) -> fmt::Result {
- let cx = s.cx;
- let it = s.item;
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ let cx = self.cx;
+ let it = self.item;
if_ok!(write!(fmt.buf, "<p class='location'>"));
let len = cx.current.len() - if it.is_mod() {1} else {0};
for (i, name) in cx.current.iter().take(len).enumerate() {
}
impl<'a> fmt::Show for Source<'a> {
- fn fmt(s: &Source<'a>, fmt: &mut fmt::Formatter) -> fmt::Result {
- let Source(s) = *s;
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ let Source(s) = *self;
let lines = s.lines().len();
let mut cols = 0;
let mut tmp = lines;
use std::char;
use std::cmp;
use std::fmt;
+use std::fmt::Show;
use std::option::{Option, Some, None};
use std::to_str::ToStr;
impl fmt::Show for Identifier {
#[inline]
- fn fmt(version: &Identifier, f: &mut fmt::Formatter) -> fmt::Result {
- match *version {
- Numeric(ref n) => fmt::Show::fmt(n, f),
- AlphaNumeric(ref s) => fmt::Show::fmt(s, f)
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
+ Numeric(ref n) => n.fmt(f),
+ AlphaNumeric(ref s) => s.fmt(f)
}
}
}
impl fmt::Show for Version {
#[inline]
- fn fmt(version: &Version, f: &mut fmt::Formatter) -> fmt::Result {
- if_ok!(write!(f.buf, "{}.{}.{}", version.major, version.minor, version.patch))
- if !version.pre.is_empty() {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ if_ok!(write!(f.buf, "{}.{}.{}", self.major, self.minor, self.patch))
+ if !self.pre.is_empty() {
if_ok!(write!(f.buf, "-"));
- for (i, x) in version.pre.iter().enumerate() {
+ for (i, x) in self.pre.iter().enumerate() {
if i != 0 { if_ok!(write!(f.buf, ".")) };
- if_ok!(fmt::Show::fmt(x, f));
+ if_ok!(x.fmt(f));
}
}
- if !version.build.is_empty() {
+ if !self.build.is_empty() {
if_ok!(write!(f.buf, "+"));
- for (i, x) in version.build.iter().enumerate() {
+ for (i, x) in self.build.iter().enumerate() {
if i != 0 { if_ok!(write!(f.buf, ".")) };
- if_ok!(fmt::Show::fmt(x, f));
+ if_ok!(x.fmt(f));
}
}
Ok(())
# mod fmt { pub type Result = (); }
# struct T;
# trait SomeName<T> {
-fn fmt(value: &T, f: &mut std::fmt::Formatter) -> fmt::Result;
+fn fmt(&self, f: &mut std::fmt::Formatter) -> fmt::Result;
# }
```
-Your type will be passed by-reference in `value`, and then the function should
+Your type will be passed as `self` by-reference, and then the function should
emit output into the `f.buf` stream. It is up to each format trait
implementation to correctly adhere to the requested formatting parameters. The
values of these parameters will be listed in the fields of the `Formatter`
}
impl fmt::Show for Vector2D {
- fn fmt(obj: &Vector2D, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// The `f.buf` value is of the type `&mut io::Writer`, which is what th
// write! macro is expecting. Note that this formatting ignores the
// various flags provided to format strings.
- write!(f.buf, "({}, {})", obj.x, obj.y)
+ write!(f.buf, "({}, {})", self.x, self.y)
}
}
// Different traits allow different forms of output of a type. The meaning of
// this format is to print the magnitude of a vector.
impl fmt::Binary for Vector2D {
- fn fmt(obj: &Vector2D, f: &mut fmt::Formatter) -> fmt::Result {
- let magnitude = (obj.x * obj.x + obj.y * obj.y) as f64;
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ let magnitude = (self.x * self.x + self.y * self.y) as f64;
let magnitude = magnitude.sqrt();
// Respect the formatting flags by using the helper method
/// to this trait. There is not an explicit way of selecting this trait to be
/// used for formatting, it is only if no other format is specified.
#[allow(missing_doc)]
-pub trait Show { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Show { fn fmt(&self, &mut Formatter) -> Result; }
/// Format trait for the `b` character
#[allow(missing_doc)]
-pub trait Bool { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Bool { fn fmt(&self, &mut Formatter) -> Result; }
/// Format trait for the `c` character
#[allow(missing_doc)]
-pub trait Char { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Char { fn fmt(&self, &mut Formatter) -> Result; }
/// Format trait for the `i` and `d` characters
#[allow(missing_doc)]
-pub trait Signed { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Signed { fn fmt(&self, &mut Formatter) -> Result; }
/// Format trait for the `u` character
#[allow(missing_doc)]
-pub trait Unsigned { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Unsigned { fn fmt(&self, &mut Formatter) -> Result; }
/// Format trait for the `o` character
#[allow(missing_doc)]
-pub trait Octal { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Octal { fn fmt(&self, &mut Formatter) -> Result; }
/// Format trait for the `b` character
#[allow(missing_doc)]
-pub trait Binary { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Binary { fn fmt(&self, &mut Formatter) -> Result; }
/// Format trait for the `x` character
#[allow(missing_doc)]
-pub trait LowerHex { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait LowerHex { fn fmt(&self, &mut Formatter) -> Result; }
/// Format trait for the `X` character
#[allow(missing_doc)]
-pub trait UpperHex { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait UpperHex { fn fmt(&self, &mut Formatter) -> Result; }
/// Format trait for the `s` character
#[allow(missing_doc)]
-pub trait String { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait String { fn fmt(&self, &mut Formatter) -> Result; }
/// Format trait for the `?` character
#[allow(missing_doc)]
-pub trait Poly { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Poly { fn fmt(&self, &mut Formatter) -> Result; }
/// Format trait for the `p` character
#[allow(missing_doc)]
-pub trait Pointer { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Pointer { fn fmt(&self, &mut Formatter) -> Result; }
/// Format trait for the `f` character
#[allow(missing_doc)]
-pub trait Float { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Float { fn fmt(&self, &mut Formatter) -> Result; }
/// Format trait for the `e` character
#[allow(missing_doc)]
-pub trait LowerExp { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait LowerExp { fn fmt(&self, &mut Formatter) -> Result; }
/// Format trait for the `E` character
#[allow(missing_doc)]
-pub trait UpperExp { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait UpperExp { fn fmt(&self, &mut Formatter) -> Result; }
// FIXME #11938 - UFCS would make us able call the above methods
// directly Show::show(x, fmt).
$(
#[doc(hidden)]
pub fn $name<T: $trait_>(x: &T, fmt: &mut Formatter) -> Result {
- $trait_::fmt(x, fmt)
+ x.fmt(fmt)
}
)*
}
/// (such as for select), then it invokes this method.
#[doc(hidden)] #[inline]
pub fn argumentstr<'a>(s: &'a &str) -> Argument<'a> {
- argument(String::fmt, s)
+ argument(secret_string, s)
}
/// When the compiler determines that the type of an argument *must* be a uint
/// (such as for plural), then it invokes this method.
#[doc(hidden)] #[inline]
pub fn argumentuint<'a>(s: &'a uint) -> Argument<'a> {
- argument(Unsigned::fmt, s)
+ argument(secret_unsigned, s)
}
// Implementations of the core formatting traits
impl Bool for bool {
- fn fmt(b: &bool, f: &mut Formatter) -> Result {
- String::fmt(&(if *b {"true"} else {"false"}), f)
+ fn fmt(&self, f: &mut Formatter) -> Result {
+ secret_string(&(if *self {"true"} else {"false"}), f)
}
}
impl<'a, T: str::Str> String for T {
- fn fmt(s: &T, f: &mut Formatter) -> Result {
- f.pad(s.as_slice())
+ fn fmt(&self, f: &mut Formatter) -> Result {
+ f.pad(self.as_slice())
}
}
impl Char for char {
- fn fmt(c: &char, f: &mut Formatter) -> Result {
+ fn fmt(&self, f: &mut Formatter) -> Result {
let mut utf8 = [0u8, ..4];
- let amt = c.encode_utf8(utf8);
+ let amt = self.encode_utf8(utf8);
let s: &str = unsafe { cast::transmute(utf8.slice_to(amt)) };
- String::fmt(&s, f)
+ secret_string(&s, f)
}
}
macro_rules! int_base(($ty:ident, $into:ident, $base:expr,
$name:ident, $prefix:expr) => {
impl $name for $ty {
- fn fmt(c: &$ty, f: &mut Formatter) -> Result {
- ::$into::to_str_bytes(*c as $into, $base, |buf| {
+ fn fmt(&self, f: &mut Formatter) -> Result {
+ ::$into::to_str_bytes(*self as $into, $base, |buf| {
f.pad_integral(buf, $prefix, true)
})
}
})
macro_rules! upper_hex(($ty:ident, $into:ident) => {
impl UpperHex for $ty {
- fn fmt(c: &$ty, f: &mut Formatter) -> Result {
- ::$into::to_str_bytes(*c as $into, 16, |buf| {
+ fn fmt(&self, f: &mut Formatter) -> Result {
+ ::$into::to_str_bytes(*self as $into, 16, |buf| {
upperhex(buf, f)
})
}
// Signed is special because it actuall emits the negative sign,
// nothing else should do that, however.
impl Signed for $signed {
- fn fmt(c: &$signed, f: &mut Formatter) -> Result {
- ::$unsigned::to_str_bytes(c.abs() as $unsigned, 10, |buf| {
- f.pad_integral(buf, "", *c >= 0)
+ fn fmt(&self, f: &mut Formatter) -> Result {
+ ::$unsigned::to_str_bytes(self.abs() as $unsigned, 10, |buf| {
+ f.pad_integral(buf, "", *self >= 0)
})
}
}
macro_rules! floating(($ty:ident) => {
impl Float for $ty {
- fn fmt(f: &$ty, fmt: &mut Formatter) -> Result {
+ fn fmt(&self, fmt: &mut Formatter) -> Result {
// FIXME: this shouldn't perform an allocation
let s = match fmt.precision {
- Some(i) => ::$ty::to_str_exact(f.abs(), i),
- None => ::$ty::to_str_digits(f.abs(), 6)
+ Some(i) => ::$ty::to_str_exact(self.abs(), i),
+ None => ::$ty::to_str_digits(self.abs(), 6)
};
- fmt.pad_integral(s.as_bytes(), "", *f >= 0.0)
+ fmt.pad_integral(s.as_bytes(), "", *self >= 0.0)
}
}
impl LowerExp for $ty {
- fn fmt(f: &$ty, fmt: &mut Formatter) -> Result {
+ fn fmt(&self, fmt: &mut Formatter) -> Result {
// FIXME: this shouldn't perform an allocation
let s = match fmt.precision {
- Some(i) => ::$ty::to_str_exp_exact(f.abs(), i, false),
- None => ::$ty::to_str_exp_digits(f.abs(), 6, false)
+ Some(i) => ::$ty::to_str_exp_exact(self.abs(), i, false),
+ None => ::$ty::to_str_exp_digits(self.abs(), 6, false)
};
- fmt.pad_integral(s.as_bytes(), "", *f >= 0.0)
+ fmt.pad_integral(s.as_bytes(), "", *self >= 0.0)
}
}
impl UpperExp for $ty {
- fn fmt(f: &$ty, fmt: &mut Formatter) -> Result {
+ fn fmt(&self, fmt: &mut Formatter) -> Result {
// FIXME: this shouldn't perform an allocation
let s = match fmt.precision {
- Some(i) => ::$ty::to_str_exp_exact(f.abs(), i, true),
- None => ::$ty::to_str_exp_digits(f.abs(), 6, true)
+ Some(i) => ::$ty::to_str_exp_exact(self.abs(), i, true),
+ None => ::$ty::to_str_exp_digits(self.abs(), 6, true)
};
- fmt.pad_integral(s.as_bytes(), "", *f >= 0.0)
+ fmt.pad_integral(s.as_bytes(), "", *self >= 0.0)
}
}
})
floating!(f64)
impl<T> Poly for T {
- fn fmt(t: &T, f: &mut Formatter) -> Result {
+ fn fmt(&self, f: &mut Formatter) -> Result {
match (f.width, f.precision) {
(None, None) => {
- repr::write_repr(f.buf, t)
+ repr::write_repr(f.buf, self)
}
// If we have a specified width for formatting, then we have to make
// this allocation of a new string
_ => {
- let s = repr::repr_to_str(t);
+ let s = repr::repr_to_str(self);
f.pad(s)
}
}
}
impl<T> Pointer for *T {
- fn fmt(t: &*T, f: &mut Formatter) -> Result {
+ fn fmt(&self, f: &mut Formatter) -> Result {
f.flags |= 1 << (parse::FlagAlternate as uint);
- ::uint::to_str_bytes(*t as uint, 16, |buf| {
+ ::uint::to_str_bytes(*self as uint, 16, |buf| {
f.pad_integral(buf, "0x", true)
})
}
}
impl<T> Pointer for *mut T {
- fn fmt(t: &*mut T, f: &mut Formatter) -> Result {
- Pointer::fmt(&(*t as *T), f)
+ fn fmt(&self, f: &mut Formatter) -> Result {
+ secret_pointer(&(*self as *T), f)
}
}
macro_rules! delegate(($ty:ty to $other:ident) => {
impl<'a> Show for $ty {
- fn fmt(me: &$ty, f: &mut Formatter) -> Result {
- $other::fmt(me, f)
+ fn fmt(&self, f: &mut Formatter) -> Result {
+ (concat_idents!(secret_, $other)(self, f))
}
}
})
-delegate!(int to Signed)
-delegate!( i8 to Signed)
-delegate!(i16 to Signed)
-delegate!(i32 to Signed)
-delegate!(i64 to Signed)
-delegate!(uint to Unsigned)
-delegate!( u8 to Unsigned)
-delegate!( u16 to Unsigned)
-delegate!( u32 to Unsigned)
-delegate!( u64 to Unsigned)
-delegate!(~str to String)
-delegate!(&'a str to String)
-delegate!(bool to Bool)
-delegate!(char to Char)
-delegate!(f32 to Float)
-delegate!(f64 to Float)
+delegate!(int to signed)
+delegate!( i8 to signed)
+delegate!(i16 to signed)
+delegate!(i32 to signed)
+delegate!(i64 to signed)
+delegate!(uint to unsigned)
+delegate!( u8 to unsigned)
+delegate!( u16 to unsigned)
+delegate!( u32 to unsigned)
+delegate!( u64 to unsigned)
+delegate!(~str to string)
+delegate!(&'a str to string)
+delegate!(bool to bool)
+delegate!(char to char)
+delegate!(f32 to float)
+delegate!(f64 to float)
impl<T> Show for *T {
- fn fmt(me: &*T, f: &mut Formatter) -> Result { Pointer::fmt(me, f) }
+ fn fmt(&self, f: &mut Formatter) -> Result { secret_pointer(self, f) }
}
impl<T> Show for *mut T {
- fn fmt(me: &*mut T, f: &mut Formatter) -> Result { Pointer::fmt(me, f) }
+ fn fmt(&self, f: &mut Formatter) -> Result { secret_pointer(self, f) }
}
// If you expected tests to be here, look instead at the run-pass/ifmt.rs test,
}
impl fmt::Show for IoError {
- fn fmt(err: &IoError, fmt: &mut fmt::Formatter) -> fmt::Result {
- if_ok!(fmt.buf.write_str(err.desc));
- match err.detail {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ if_ok!(fmt.buf.write_str(self.desc));
+ match self.detail {
Some(ref s) => write!(fmt.buf, " ({})", *s),
None => Ok(())
}
impl fmt::Show for ProcessExit {
/// Format a ProcessExit enum, to nicely present the information.
- fn fmt(obj: &ProcessExit, f: &mut fmt::Formatter) -> fmt::Result {
- match *obj {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
ExitStatus(code) => write!(f.buf, "exit code: {}", code),
ExitSignal(code) => write!(f.buf, "signal: {}", code),
}
impl<T: fmt::Show> fmt::Show for Option<T> {
#[inline]
- fn fmt(s: &Option<T>, f: &mut fmt::Formatter) -> fmt::Result {
- match *s {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
Some(ref t) => write!(f.buf, "Some({})", *t),
None => write!(f.buf, "None")
}
}
impl fmt::Show for MapError {
- fn fmt(val: &MapError, out: &mut fmt::Formatter) -> fmt::Result {
- let str = match *val {
+ fn fmt(&self, out: &mut fmt::Formatter) -> fmt::Result {
+ let str = match *self {
ErrFdNotAvail => "fd not available for reading or writing",
ErrInvalidFd => "Invalid fd",
ErrUnaligned => {
}
impl<'a, P: GenericPath> fmt::Show for Display<'a, P> {
- fn fmt(d: &Display<P>, f: &mut fmt::Formatter) -> fmt::Result {
- d.with_str(|s| f.pad(s))
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ self.with_str(|s| f.pad(s))
}
}
impl<T: fmt::Show, E: fmt::Show> fmt::Show for Result<T, E> {
#[inline]
- fn fmt(s: &Result<T, E>, f: &mut fmt::Formatter) -> fmt::Result {
- match *s {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
Ok(ref t) => write!(f.buf, "Ok({})", *t),
Err(ref e) => write!(f.buf, "Err({})", *e)
}
}
impl fmt::Show for InternedString {
- fn fmt(obj: &InternedString, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f.buf, "{}", obj.string.as_slice())
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f.buf, "{}", self.string.as_slice())
}
}
struct B;
impl fmt::Signed for A {
- fn fmt(_: &A, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.buf.write("aloha".as_bytes())
}
}
impl fmt::Signed for B {
- fn fmt(_: &B, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.buf.write("adios".as_bytes())
}
}
struct Foo(Cell<int>);
impl fmt::Show for Foo {
- fn fmt(f: &Foo, _fmt: &mut fmt::Formatter) -> fmt::Result {
- let Foo(ref f) = *f;
+ fn fmt(&self, _fmt: &mut fmt::Formatter) -> fmt::Result {
+ let Foo(ref f) = *self;
assert!(f.get() == 0);
f.set(1);
Ok(())