官术网_书友最值得收藏!

  • Learning Rust
  • Paul Johnson Vesa Kaihlavirta
  • 123字
  • 2021-07-02 23:07:21

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.

主站蜘蛛池模板: 武陟县| 天津市| 定陶县| 庆安县| 江华| 大渡口区| 巢湖市| 霍州市| 武城县| 资中县| 呈贡县| 饶河县| 衡东县| 花莲县| 盐源县| 东莞市| 商洛市| 鹤岗市| 夏津县| 从化市| 洪江市| 平凉市| 肃北| 涞源县| 灵寿县| 桑植县| 饶河县| 邯郸县| 额尔古纳市| 镇江市| 尼勒克县| 广灵县| 巫山县| 泗阳县| 息烽县| 太和县| 达拉特旗| 陇川县| 融水| 白朗县| 台南县|