Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis
Created October 9, 2019 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikomatsakis/b74e9675a3e663bab98a4a3b1f339278 to your computer and use it in GitHub Desktop.
Save nikomatsakis/b74e9675a3e663bab98a4a3b1f339278 to your computer and use it in GitHub Desktop.
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