Macro enso_prelude::iformat[][src]

macro_rules! iformat {
    #[proc_macro_hack(fake_call_site)] => { ... };
}
Expand description

Creates a String by interpolating inline expressions.

Works by expanding to format!.

// Out-of-literal style (preferred)
iformat!("x plus y is " x + y ".") == format!("x plus y is {}.", x + y)
iformat!("foo: " foo;? ", bar: " bar;#?) == format!("foo: {:?}, bar: {:#?}", foo, bar)

// In-literal style (old)
iformat!("x plus y is {x + y}.") == format!("x plus y is {}.", x + y)
iformat!("foo: {foo:?}, bar: {bar:#?}") == format!("foo: {:?}, bar: {:#?}", foo, bar)

Out-of-literal format specs are roughly the same as in std::fmt, except:

  • they are preceded by a ; rather than a :
  • format parameterization (for width/precision) is not yet supported, literals must be used
  • since 3.4e/3.4E (as in format!("{:3.4e}", x)) is invalid in rust (exponent is missing), 3.4 e (with a space) or 3.4s must be used instead
  • The fill character for padding must be a char literal: iformat!("padded: " inside_dashes;'-'^30)

In-literal format specs are identical to those found in std::fmt, except that they also do not support format parameterization.