Named parameters

As shown in the formatting table, it is possible to use a named parameter. The operation of these is similar to a positional parameter; the difference, though, is that a named parameter is used. This is very useful in ensuring that the value output in the string is the correct parameter.

It is perfectly acceptable to use an empty parameter within a formatted string when using a named parameter, for example:

format!("{b} {a} {} {t}", b = "B", a = 'a', t = 33); 

The rules for handling non-positional parameters alongside named parameters are similar to the rules for positional parameters: the named parameters are ignored when figuring out the positions. This will, therefore, give the output B a B 33.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset