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

Optional quantifier

In the macro_rules system, there's no way to specify that a pattern is optional, like with the ? quantifier in regular expressions. If we wanted to allow the user of our hash macro to use a trailing comma, we could change the rule by moving the comma inside the parentheses: ($( $key:expr => $value:expr,)*).

However, it will force the user to write a trailing macro. If we want to allow both variants, we can use the following trick, which uses the * operator: ($( $key:expr => $value:expr ),* $(,)* ).

This means that a comma must be used between each pattern and we can use any number of commas after the last pattern, including no comma at all.

主站蜘蛛池模板: 米林县| 自治县| 青海省| 任丘市| 沙湾县| 信阳市| 阳高县| 澄江县| 阿拉善盟| 澄江县| 镇坪县| 上蔡县| 盐边县| 浮梁县| 枞阳县| 舟山市| 隆安县| 石棉县| 雷山县| 平舆县| 天台县| 溆浦县| 永宁县| 平乡县| 庄河市| 沈阳市| 柏乡县| 左贡县| 崇州市| 南平市| 卢湾区| 葵青区| 承德县| 通城县| 河北区| 绥宁县| 虹口区| 建水县| 商城县| 静海县| 横峰县|