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

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.

主站蜘蛛池模板: 剑阁县| 义乌市| 白沙| 甘泉县| 冷水江市| 余姚市| 龙山县| 花莲县| 交城县| 宣城市| 江源县| 金门县| 罗甸县| 富蕴县| 宁武县| 大田县| 开平市| 桃江县| 大宁县| 龙胜| 时尚| 若羌县| 新和县| 贞丰县| 策勒县| 屏南县| 泗洪县| 铁岭县| 通辽市| 房产| 靖州| 汶川县| 土默特左旗| 象山县| 昆明市| 德惠市| 达州市| 宁波市| 西充县| 长治市| 平塘县|