File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -107,3 +107,28 @@ macro_rules! format {
107107 res
108108 } }
109109}
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 {
15851585 let slice = self . vec . into_boxed_slice ( ) ;
15861586 unsafe { from_boxed_utf8_unchecked ( slice) }
15871587 }
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+ }
15881594}
15891595
15901596impl FromUtf8Error {
Original file line number Diff line number Diff line change 261261#![ feature( external_doc) ]
262262#![ feature( fn_traits) ]
263263#![ feature( format_args_nl) ]
264+ #![ feature( format_to) ]
264265#![ feature( gen_future) ]
265266#![ feature( generator_trait) ]
266267#![ feature( global_asm) ]
@@ -373,6 +374,8 @@ pub use alloc_crate::boxed;
373374pub use alloc_crate:: fmt;
374375#[ stable( feature = "rust1" , since = "1.0.0" ) ]
375376pub use alloc_crate:: format;
377+ #[ unstable( feature = "format_to" , issue = "none" , reason = "new API" ) ]
378+ pub use alloc_crate:: format_to;
376379#[ stable( feature = "rust1" , since = "1.0.0" ) ]
377380pub use alloc_crate:: rc;
378381#[ stable( feature = "rust1" , since = "1.0.0" ) ]
You can’t perform that action at this time.
0 commit comments