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

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.

主站蜘蛛池模板: 饶阳县| 宝清县| 鹰潭市| 改则县| 上犹县| 廊坊市| 新平| 威远县| 高密市| 东乡| 三门县| 金塔县| 横峰县| 宜君县| 酉阳| 龙江县| 友谊县| 庆城县| 正定县| 万载县| 巴南区| 东丰县| 揭西县| 麻阳| 侯马市| 淮南市| 望城县| 大邑县| 宜昌市| 徐闻县| 孟州市| 镇坪县| 察隅县| 北海市| 新津县| 武冈市| 庆安县| 吴桥县| 峡江县| 芷江| 岳阳县|