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

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.

主站蜘蛛池模板: 彭阳县| 磐安县| 景谷| 石屏县| 巧家县| 霍城县| 阿图什市| 定西市| 合作市| 宾阳县| 福鼎市| 通榆县| 孙吴县| 阿城市| 呈贡县| 方城县| 泸定县| 松江区| 紫云| 凤翔县| 江陵县| 通海县| 遵化市| 咸宁市| 天气| 崇州市| 修水县| 德钦县| 海淀区| 连南| 云和县| 中山市| 普洱| 尉氏县| 阿荣旗| 顺义区| 宿迁市| 永平县| 安泽县| 石柱| 普安县|