interpolator
Runtime implementation of format!
.
format
Runtime version of format!
.
Takes a string and a context, containing Formattable
values, returns a
string.
use HashMap;
use ;
let formatted = format
.unwrap;
assert_eq!;
write
Runtime version of write!
.
Takes a mutable Write
e.g. &mut String
, a format string and a context,
containing Formattable
values.
use HashMap;
use ;
let mut buf = String new;
write
.unwrap;
assert_eq!;
i
iter format
The feature iter
enables an additional format trait i
, it allows to
format a list of values with a format string and an optional join
expression.
The syntax is {list:i(the format string, '{}' is the array element)(the join)}
, an empty join can also be omitted {list:i({})}
. If join is omitted
the format string {}
can be omitted as well {list:i}
.
Should you need to use )
inside your format string or join, you can add #
similar to rust's raw string
(i.e. #(({}))#
).
It is also possible to only iterate a sub-slice specified through a range
before the format string, i.e. {list:i1..4}
. For open ranges range
bounds can also be omitted. To index from the end, you can use negative
range bounds.
It is also possible to index a single value by only specifying an isize
{list:i1}
.
A Formattable
implementing iter is created using Formattable::iter
:
// HashMap macro
use hash;
use ;
// Needs to be a slice of references because `Formattable::display` expects a
// reference
let items = .map;
let items = iter;
let format_str = "Greetings: {items:i..-1(`{it}`)(, )} and {items:i-1..(`{it}`)}";
assert_eq!;
# return Ok::
Features
By default only Display
is supported, the rest of the
formatting traits
can be enabled through the following features.
debug
enables?
,x?
andX?
trait specifiersnumber
enablesx
,X
,b
,o
,e
andE
trait specifierspointer
enablesp
trait specifiersiter
enablesi
trait specifier