1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
#![cfg_attr(feature = "nightly",
    feature(external_doc)
)]
#![cfg_attr(feature = "nightly",
    doc(include = "../README.md")
)]
#![cfg_attr(not(feature = "nightly"),
    doc = "See [crates.io](https://crates.io/crates/fstrings)"
)]
#![cfg_attr(not(feature = "nightly"),
    doc = "for more info about this crate."
)]

#![no_std]

extern crate proc_macro;

mod doctest_readme {
    macro_rules! with_doc {(
        #[doc = $doc_string:expr]
        $item:item
    ) => (
        #[doc = $doc_string]
        $item
    )}

    with_doc! {
        #[doc = include_str!("../README.md")]
        extern {}
    }
}

macro_rules! mk_macros {( @with_dollar![$dol:tt]=>
    $(
        #[doc = $doc_string:literal]
        $printlnf:ident
            => $println:ident!($($stream:ident,)? ...)
        ,
    )*
) => (
    $(
        #[doc = $doc_string]
        #[macro_export]
        macro_rules! $printlnf {(
            $($dol $stream : expr,)? $dol($dol args:tt)*
        ) => (
            $println!($($dol $stream,)? "{}", format_args_f!($dol($dol args)*))
        )}
    )*
)}

mk_macros! { @with_dollar![$]=>
    #[doc = "Like [`print!`](https://doc.rust-lang.org/std/macro.print.html), but with basic f-string interpolation."]
    print_f
        => print!(...)
    ,
    #[doc = "Like [`println!`](https://doc.rust-lang.org/std/macro.println.html), but with basic f-string interpolation."]
    println_f
        => println!(...)
    ,
    #[doc = "Like [`eprint!`](https://doc.rust-lang.org/std/macro.eprint.html), but with basic f-string interpolation."]
    eprint_f
        => eprint!(...)
    ,
    #[doc = "Like [`eprintln!`](https://doc.rust-lang.org/std/macro.eprintln.html), but with basic f-string interpolation."]
    eprintln_f
        => eprintln!(...)
    ,
    #[doc = "Like [`format!`](https://doc.rust-lang.org/std/macro.format.html), but with basic f-string interpolation."]
    format_f
        => format!(...)
    ,
    #[doc = "Shorthand for [`format_f`]."]
    f
        => format!(...)
    ,
    #[doc = "Like [`panic!`](https://doc.rust-lang.org/std/macro.panic.html), but with basic f-string interpolation."]
    panic_f
        => panic!(...)
    ,
    #[doc = "Like [`unreachable!`](https://doc.rust-lang.org/std/macro.unreachable.html), but with basic f-string interpolation."]
    unreachable_f
        => unreachable!(...)
    ,
    #[doc = "Like [`unimplemented!`](https://doc.rust-lang.org/std/macro.unimplemented.html), but with basic f-string interpolation."]
    unimplemented_f
        => unimplemented!(...)
    ,
    #[doc = "Like [`write!`](https://doc.rust-lang.org/std/macro.write.html), but with basic f-string interpolation."]
    write_f
        => write!(stream, ...)
    ,
    #[doc = "Like [`writeln!`](https://doc.rust-lang.org/std/macro.writeln.html), but with basic f-string interpolation."]
    writeln_f
        => writeln!(stream, ...)
    ,
}

/// Like [`format_args!`](
/// https://doc.rust-lang.org/std/macro.format_args.html),
/// but with basic f-string interpolation.
#[::proc_macro_hack::proc_macro_hack(fake_call_site)]
pub use proc_macro::format_args_f;