@@ -36,7 +36,7 @@ Some examples of the `format!` extension are:
36
36
format!("Hello") // => ~"Hello"
37
37
format!("Hello, {:s}!", "world") // => ~"Hello, world!"
38
38
format!("The number is {:d}", 1) // => ~"The number is 1"
39
- format!("{:? }", ~[3, 4]) // => ~"~[3, 4]"
39
+ format!("{}", ~[3, 4]) // => ~"~[3, 4]"
40
40
format!("{value}", value=4) // => ~"4"
41
41
format!("{} {}", 1, 2) // => ~"1 2"
42
42
~~~
@@ -363,32 +363,6 @@ pub struct Argument<'self> {
363
363
priv value : & ' self util:: Void ,
364
364
}
365
365
366
- impl < ' self > Arguments < ' self > {
367
- /// When using the format_args!() macro, this function is used to generate the
368
- /// Arguments structure. The compiler inserts an `unsafe` block to call this,
369
- /// which is valid because the compiler performs all necessary validation to
370
- /// ensure that the resulting call to format/write would be safe.
371
- #[ doc( hidden) ] #[ inline]
372
- pub unsafe fn new < ' a > ( fmt : & ' static [ rt:: Piece < ' static > ] ,
373
- args : & ' a [ Argument < ' a > ] ) -> Arguments < ' a > {
374
- Arguments { fmt : cast:: transmute ( fmt) , args : args }
375
- }
376
- }
377
-
378
- /// This structure represents a safely precompiled version of a format string
379
- /// and its arguments. This cannot be generated at runtime because it cannot
380
- /// safely be done so, so no constructors are given and the fields are private
381
- /// to prevent modification.
382
- ///
383
- /// The `format_args!` macro will safely create an instance of this structure
384
- /// and pass it to a user-supplied function. The macro validates the format
385
- /// string at compile-time so usage of the `write` and `format` functions can
386
- /// be safely performed.
387
- pub struct Arguments < ' self > {
388
- priv fmt: & ' self [ rt:: Piece < ' self > ] ,
389
- priv args : & ' self [ Argument < ' self > ] ,
390
- }
391
-
392
366
/// When a format is not otherwise specified, types are formatted by ascribing
393
367
/// to this trait. There is not an explicit way of selecting this trait to be
394
368
/// used for formatting, it is only if no other format is specified.
@@ -436,26 +410,6 @@ pub trait Float { fn fmt(&Self, &mut Formatter); }
436
410
/// and a list of arguments. The arguments will be formatted according to the
437
411
/// specified format string into the output stream provided.
438
412
///
439
- /// # Arguments
440
- ///
441
- /// * output - the buffer to write output to
442
- /// * args - the precompiled arguments generated by `format_args!`
443
- ///
444
- /// # Example
445
- ///
446
- /// ~~~{.rust}
447
- /// use std::fmt;
448
- /// let w: &mut io::Writer = ...;
449
- /// format_args!(|args| { fmt::write(w, args) }, "Hello, {}!", "world");
450
- /// ~~~
451
- pub fn write ( output : & mut io:: Writer , args : & Arguments ) {
452
- unsafe { write_unsafe ( output, args. fmt , args. args ) }
453
- }
454
-
455
- /// The `write_unsafe` function takes an output stream, a precompiled format
456
- /// string, and a list of arguments. The arguments will be formatted according
457
- /// to the specified format string into the output stream provided.
458
- ///
459
413
/// See the documentation for `format` for why this function is unsafe and care
460
414
/// should be taken if calling it manually.
461
415
///
@@ -472,9 +426,8 @@ pub fn write(output: &mut io::Writer, args: &Arguments) {
472
426
///
473
427
/// Note that this function assumes that there are enough arguments for the
474
428
/// format string.
475
- pub unsafe fn write_unsafe ( output : & mut io:: Writer ,
476
- fmt : & [ rt:: Piece ] ,
477
- args : & [ Argument ] ) {
429
+ pub unsafe fn write ( output : & mut io:: Writer ,
430
+ fmt : & [ rt:: Piece ] , args : & [ Argument ] ) {
478
431
let mut formatter = Formatter {
479
432
flags : 0 ,
480
433
width : None ,
@@ -493,25 +446,6 @@ pub unsafe fn write_unsafe(output: &mut io::Writer,
493
446
/// The format function takes a precompiled format string and a list of
494
447
/// arguments, to return the resulting formatted string.
495
448
///
496
- /// # Arguments
497
- ///
498
- /// * args - a structure of arguments generated via the `format_args!` macro.
499
- /// Because this structure can only be safely generated at
500
- /// compile-time, this function is safe.
501
- ///
502
- /// # Example
503
- ///
504
- /// ~~~{.rust}
505
- /// use std::fmt;
506
- /// let s = format_args!(fmt::format, "Hello, {}!", "world");
507
- /// assert_eq!(s, "Hello, world!");
508
- /// ~~~
509
- pub fn format ( args : & Arguments ) -> ~str {
510
- unsafe { format_unsafe ( args. fmt , args. args ) }
511
- }
512
-
513
- /// The unsafe version of the formatting function.
514
- ///
515
449
/// This is currently an unsafe function because the types of all arguments
516
450
/// aren't verified by immediate callers of this function. This currently does
517
451
/// not validate that the correct types of arguments are specified for each
@@ -531,9 +465,9 @@ pub fn format(args: &Arguments) -> ~str {
531
465
///
532
466
/// Note that this function assumes that there are enough arguments for the
533
467
/// format string.
534
- pub unsafe fn format_unsafe ( fmt : & [ rt:: Piece ] , args : & [ Argument ] ) -> ~str {
468
+ pub unsafe fn format ( fmt : & [ rt:: Piece ] , args : & [ Argument ] ) -> ~str {
535
469
let mut output = MemWriter :: new ( ) ;
536
- write_unsafe ( & mut output as & mut io:: Writer , fmt, args) ;
470
+ write ( & mut output as & mut io:: Writer , fmt, args) ;
537
471
return str:: from_utf8_owned ( output. inner ( ) ) ;
538
472
}
539
473
@@ -806,7 +740,7 @@ impl<'self> Formatter<'self> {
806
740
807
741
/// This is a function which calls are emitted to by the compiler itself to
808
742
/// create the Argument structures that are passed into the `format` function.
809
- #[ doc( hidden) ] # [ inline ]
743
+ #[ doc( hidden) ]
810
744
pub fn argument < ' a , T > ( f : extern "Rust" fn ( & T , & mut Formatter ) ,
811
745
t : & ' a T ) -> Argument < ' a > {
812
746
unsafe {
@@ -819,14 +753,14 @@ pub fn argument<'a, T>(f: extern "Rust" fn(&T, &mut Formatter),
819
753
820
754
/// When the compiler determines that the type of an argument *must* be a string
821
755
/// (such as for select), then it invokes this method.
822
- #[ doc( hidden) ] # [ inline ]
756
+ #[ doc( hidden) ]
823
757
pub fn argumentstr < ' a > ( s : & ' a & str ) -> Argument < ' a > {
824
758
argument ( String :: fmt, s)
825
759
}
826
760
827
761
/// When the compiler determines that the type of an argument *must* be a uint
828
762
/// (such as for plural), then it invokes this method.
829
- #[ doc( hidden) ] # [ inline ]
763
+ #[ doc( hidden) ]
830
764
pub fn argumentuint < ' a > ( s : & ' a uint ) -> Argument < ' a > {
831
765
argument ( Unsigned :: fmt, s)
832
766
}
@@ -965,8 +899,14 @@ impl<T> Pointer for *T {
965
899
}
966
900
}
967
901
}
902
+
968
903
impl < T > Pointer for * mut T {
969
- fn fmt ( t : & * mut T , f : & mut Formatter ) { Pointer :: fmt ( & ( * t as * T ) , f) }
904
+ fn fmt ( t : & * mut T , f : & mut Formatter ) {
905
+ f. flags |= 1 << ( parse:: FlagAlternate as uint ) ;
906
+ do :: uint:: to_str_bytes ( * t as uint , 16 ) |buf| {
907
+ f. pad_integral ( buf, "0x" , true ) ;
908
+ }
909
+ }
970
910
}
971
911
972
912
// Implementation of Default for various core types
@@ -1000,6 +940,7 @@ delegate!(f64 to Float)
1000
940
impl < T > Default for * T {
1001
941
fn fmt ( me : & * T , f : & mut Formatter ) { Pointer :: fmt ( me, f) }
1002
942
}
943
+
1003
944
impl < T > Default for * mut T {
1004
945
fn fmt ( me : & * mut T , f : & mut Formatter ) { Pointer :: fmt ( me, f) }
1005
946
}
0 commit comments