/// Arguments structure. The compiler inserts an `unsafe` block to call this,
/// which is valid because the compiler performs all necessary validation to
/// ensure that the resulting call to format/write would be safe.
- #[cfg(not(stage0))]
#[doc(hidden)] #[inline]
pub unsafe fn new<'a>(pieces: &'static [&'static str],
args: &'a [Argument<'a>]) -> Arguments<'a> {
/// This function is used to specify nonstandard formatting parameters.
/// The `pieces` array must be at least as long as `fmt` to construct
/// a valid Arguments structure.
- #[cfg(not(stage0))]
#[doc(hidden)] #[inline]
pub unsafe fn with_placeholders<'a>(pieces: &'static [&'static str],
fmt: &'static [rt::Argument<'static>],
args: args
}
}
-
- #[cfg(stage0)]
- #[doc(hidden)] #[inline]
- pub unsafe fn new<'a>(fmt: &'static [rt::Piece<'static>],
- args: &'a [Argument<'a>]) -> Arguments<'a> {
- Arguments{ fmt: mem::transmute(fmt), args: args }
- }
}
/// This structure represents a safely precompiled version of a format string
/// and pass it to a function or closure, passed as the first argument. The
/// macro validates the format string at compile-time so usage of the `write`
/// and `format` functions can be safely performed.
-#[cfg(not(stage0))]
pub struct Arguments<'a> {
// Format string pieces to print.
pieces: &'a [&'a str],
args: &'a [Argument<'a>],
}
-#[cfg(stage0)] #[doc(hidden)]
-pub struct Arguments<'a> {
- fmt: &'a [rt::Piece<'a>],
- args: &'a [Argument<'a>],
-}
-
impl<'a> Show for Arguments<'a> {
fn fmt(&self, fmt: &mut Formatter) -> Result {
write(fmt.buf, self)
secret_upper_exp, UpperExp;
}
-#[cfg(not(stage0))]
static DEFAULT_ARGUMENT: rt::Argument<'static> = rt::Argument {
position: rt::ArgumentNext,
format: rt::FormatSpec {
///
/// * output - the buffer to write output to
/// * args - the precompiled arguments generated by `format_args!`
-#[cfg(not(stage0))]
pub fn write(output: &mut FormatWriter, args: &Arguments) -> Result {
let mut formatter = Formatter {
flags: 0,
Ok(())
}
-#[cfg(stage0)] #[doc(hidden)]
-pub fn write(output: &mut FormatWriter, args: &Arguments) -> Result {
- let mut formatter = Formatter {
- flags: 0,
- width: None,
- precision: None,
- buf: output,
- align: rt::AlignUnknown,
- fill: ' ',
- args: args.args,
- curarg: args.args.iter(),
- };
- for piece in args.fmt.iter() {
- try!(formatter.run(piece));
- }
- Ok(())
-}
-
impl<'a> Formatter<'a> {
// First up is the collection of functions used to execute a format string
// at runtime. This consumes all of the compile-time statics generated by
// the format! syntax extension.
- #[cfg(not(stage0))]
fn run(&mut self, arg: &rt::Argument) -> Result {
// Fill in the format parameters into the formatter
self.fill = arg.format.fill;
(value.formatter)(value.value, self)
}
- #[cfg(stage0)] #[doc(hidden)]
- fn run(&mut self, piece: &rt::Piece) -> Result {
- match *piece {
- rt::String(s) => self.buf.write(s.as_bytes()),
- rt::Argument(ref arg) => {
- // Fill in the format parameters into the formatter
- self.fill = arg.format.fill;
- self.align = arg.format.align;
- self.flags = arg.format.flags;
- self.width = self.getcount(&arg.format.width);
- self.precision = self.getcount(&arg.format.precision);
-
- // Extract the correct argument
- let value = match arg.position {
- rt::ArgumentNext => { *self.curarg.next().unwrap() }
- rt::ArgumentIs(i) => self.args[i],
- };
-
- // Then actually do some printing
- (value.formatter)(value.value, self)
- }
- }
- }
-
fn getcount(&mut self, cnt: &rt::Count) -> Option<uint> {
match *cnt {
rt::CountIs(n) => { Some(n) }