move to rust 2021, tweak macro (#428)

* cargo fix --edition

* move to rust 2021

* simplify macro now that patterns are supported natively

Co-authored-by: James Wilson <james@jsdw.me>
This commit is contained in:
Dan Shields
2021-11-15 07:52:16 -07:00
committed by GitHub
parent 6e2faa43be
commit 006cf76d3b
5 changed files with 9 additions and 9 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
name = "common"
version = "0.1.0"
authors = ["Parity Technologies Ltd. <admin@parity.io>"]
edition = "2018"
edition = "2021"
license = "GPL-3.0"
[dependencies]
+1 -1
View File
@@ -2,7 +2,7 @@
name = "telemetry_core"
version = "0.1.0"
authors = ["Parity Technologies Ltd. <admin@parity.io>"]
edition = "2018"
edition = "2021"
license = "GPL-3.0"
[dependencies]
+1 -1
View File
@@ -2,7 +2,7 @@
name = "telemetry_shard"
version = "0.1.0"
authors = ["Parity Technologies Ltd. <admin@parity.io>"]
edition = "2018"
edition = "2021"
license = "GPL-3.0"
[dependencies]
+1 -1
View File
@@ -2,7 +2,7 @@
name = "test_utils"
version = "0.1.0"
authors = ["James Wilson <james@jsdw.me>"]
edition = "2018"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+5 -5
View File
@@ -43,14 +43,14 @@ assert!(does_contain);
*/
#[macro_export]
macro_rules! contains_matches {
($expression:expr, $( $( $pattern:pat )|+ $( if $guard:expr )? ),+ $(,)?) => {{
($expression:expr, $( $pattern:pat $( if $guard:expr )? ),+ $(,)?) => {{
let mut items = $expression.into_iter();
// For each pattern we want to match, we consume items until
// we find the first match, and then break the loop and do the
// same again with the next pattern. If we run out of items, we
// set the validity to false and stop trying to match. Else, we
// match againse each of the patterns and return true.
// match against each of the patterns and return true.
let mut is_valid = true;
$(
while is_valid {
@@ -63,7 +63,7 @@ macro_rules! contains_matches {
};
match item {
$( $pattern )|+ $( if $guard )? => break,
$pattern $( if $guard )? => break,
_ => continue
}
}
@@ -99,10 +99,10 @@ test_utils::assert_contains_matches!(
*/
#[macro_export]
macro_rules! assert_contains_matches {
($expression:expr, $( $( $pattern:pat )|+ $( if $guard:expr )? ),+ $(,)?) => {
($expression:expr, $( $pattern:pat $( if $guard:expr )? ),+ $(,)?) => {
let does_contain_matches = $crate::contains_matches!(
$expression,
$( $( $pattern )|+ $( if $guard )? ),+
$( $pattern $( if $guard )? ),+
);
assert!(does_contain_matches);