File tree 3 files changed +34
-0
lines changed
3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -107,3 +107,28 @@ macro_rules! format {
107
107
res
108
108
} }
109
109
}
110
+
111
+ /// Like [`format!`], but appends to an existing string
112
+ ///
113
+ ///
114
+ /// [`format!`]: crate::format
115
+ ///
116
+ /// # Examples
117
+ ///
118
+ /// ```
119
+ /// #![feature(format_to)]
120
+ ///
121
+ /// let mut buf = String::new();
122
+ /// format_to!(buf, "hello");
123
+ /// format_to!(buf, ", world!");
124
+ /// assert_eq!(buf, "hello, world!");
125
+ /// ```
126
+ #[ macro_export]
127
+ #[ unstable( feature = "format_to" , issue = "none" , reason = "new API" ) ]
128
+ #[ allow_internal_unstable( liballoc_internals) ]
129
+ macro_rules! format_to {
130
+ ( $buf: expr $( , $( $arg: tt) * ) ? ) => { {
131
+ // Redirect via method call syntax to get autoref behavior
132
+ $buf. __push_fmt( $crate:: __export:: format_args!( $( $( $arg) * ) ?) ) ;
133
+ } }
134
+ }
Original file line number Diff line number Diff line change @@ -1585,6 +1585,12 @@ impl String {
1585
1585
let slice = self . vec . into_boxed_slice ( ) ;
1586
1586
unsafe { from_boxed_utf8_unchecked ( slice) }
1587
1587
}
1588
+
1589
+ #[ unstable( feature = "liballoc_internals" , issue = "none" , reason = "implementation detail" ) ]
1590
+ #[ doc( hidden) ]
1591
+ pub fn __push_fmt ( & mut self , args : fmt:: Arguments < ' _ > ) {
1592
+ fmt:: Write :: write_fmt ( self , args) . unwrap ( ) ;
1593
+ }
1588
1594
}
1589
1595
1590
1596
impl FromUtf8Error {
Original file line number Diff line number Diff line change 261
261
#![ feature( external_doc) ]
262
262
#![ feature( fn_traits) ]
263
263
#![ feature( format_args_nl) ]
264
+ #![ feature( format_to) ]
264
265
#![ feature( gen_future) ]
265
266
#![ feature( generator_trait) ]
266
267
#![ feature( global_asm) ]
@@ -373,6 +374,8 @@ pub use alloc_crate::boxed;
373
374
pub use alloc_crate:: fmt;
374
375
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
375
376
pub use alloc_crate:: format;
377
+ #[ unstable( feature = "format_to" , issue = "none" , reason = "new API" ) ]
378
+ pub use alloc_crate:: format_to;
376
379
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
377
380
pub use alloc_crate:: rc;
378
381
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
You can’t perform that action at this time.
0 commit comments