Created
October 9, 2019 12:43
-
-
Save nikomatsakis/09ada77dd4f1569e006bdc5a2461a8c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fmt::Formatter; | |
use std::marker::PhantomData; | |
async fn foo(_: String) { | |
} | |
#[derive(Copy, Clone)] | |
pub struct Arguments<'a> { | |
// Format string pieces to print. | |
pieces: &'a [&'a str], | |
// Dynamic arguments for interpolation, to be interleaved with string | |
// pieces. (Every argument is preceded by a string piece.) | |
args: &'a [ArgumentV1<'a>], | |
} | |
pub struct ArgumentV1<'a> { | |
value: &'a Void, | |
formatter: fn(&Void, &mut Formatter<'_>) -> std::fmt::Result, | |
} | |
struct Void { | |
_priv: (), | |
//_oibit_remover: PhantomData<*mut dyn Fn()>, | |
} | |
impl<'a> Arguments<'a> { | |
/// When using the format_args!() macro, this function is used to generate the | |
/// Arguments structure. | |
#[doc(hidden)] #[inline] | |
pub fn new_v1(pieces: &'a [&'a str], args: &'a [ArgumentV1<'a>]) -> Arguments<'a> { | |
Arguments { | |
pieces, | |
args, | |
} | |
} | |
} | |
impl<'a> ArgumentV1<'a> { | |
pub fn new<'b, T>(x: &'b T, f: fn(&T, &mut Formatter<'_>) -> std::fmt::Result) -> ArgumentV1<'b> { | |
unsafe { | |
ArgumentV1 { | |
formatter: std::mem::transmute(f), | |
value: std::mem::transmute(x) | |
} | |
} | |
} | |
} | |
fn format(a: Arguments) -> String { | |
"".to_string() | |
} | |
fn bar() -> impl Send { | |
async move | |
{ | |
foo( | |
format(Arguments::new_v1( | |
&["", ":"], | |
&match (&1_i32, &2_i32) { | |
(arg0, arg1) => | |
[ArgumentV1::new(arg0, ::core::fmt::Display::fmt), | |
ArgumentV1::new(arg1, ::core::fmt::Display::fmt)], | |
}))).await; | |
} | |
} | |
fn main() { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment