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 ShieldsandJames Wilson authored and GitHub committed 2021-11-15 14:52:16 +00:00
1 parent 6e2faa43be
commit 006cf76d3b
5 files changed
+9 -9

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
name = "common" name = "common"
version = "0.1.0" version = "0.1.0"
authors = ["Parity Technologies Ltd. <admin@parity.io>"] authors = ["Parity Technologies Ltd. <admin@parity.io>"]
edition = "2018" edition = "2021"
license = "GPL-3.0" license = "GPL-3.0"
[dependencies] [dependencies]
+1 -1
View File
@@ -2,7 +2,7 @@
name = "telemetry_core" name = "telemetry_core"
version = "0.1.0" version = "0.1.0"
authors = ["Parity Technologies Ltd. <admin@parity.io>"] authors = ["Parity Technologies Ltd. <admin@parity.io>"]
edition = "2018" edition = "2021"
license = "GPL-3.0" license = "GPL-3.0"
[dependencies] [dependencies]
+1 -1
View File
@@ -2,7 +2,7 @@
name = "telemetry_shard" name = "telemetry_shard"
version = "0.1.0" version = "0.1.0"
authors = ["Parity Technologies Ltd. <admin@parity.io>"] authors = ["Parity Technologies Ltd. <admin@parity.io>"]
edition = "2018" edition = "2021"
license = "GPL-3.0" license = "GPL-3.0"
[dependencies] [dependencies]
+1 -1
View File
@@ -2,7 +2,7 @@
name = "test_utils" name = "test_utils"
version = "0.1.0" version = "0.1.0"
authors = ["James Wilson <james@jsdw.me>"] 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 # 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_export]
macro_rules! contains_matches { macro_rules! contains_matches {
($expression:expr, $( $( $pattern:pat )|+ $( if $guard:expr )? ),+ $(,)?) => {{ ($expression:expr, $( $pattern:pat $( if $guard:expr )? ),+ $(,)?) => {{
let mut items = $expression.into_iter(); let mut items = $expression.into_iter();
// For each pattern we want to match, we consume items until // For each pattern we want to match, we consume items until
// we find the first match, and then break the loop and do the // 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 // 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 // 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; let mut is_valid = true;
$( $(
while is_valid { while is_valid {
@@ -63,7 +63,7 @@ macro_rules! contains_matches {
}; };
match item { match item {
$( $pattern )|+ $( if $guard )? => break, $pattern $( if $guard )? => break,
_ => continue _ => continue
} }
} }
@@ -99,10 +99,10 @@ test_utils::assert_contains_matches!(
*/ */
#[macro_export] #[macro_export]
macro_rules! assert_contains_matches { 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!( let does_contain_matches = $crate::contains_matches!(
$expression, $expression,
$( $( $pattern )|+ $( if $guard )? ),+ $( $pattern $( if $guard )? ),+
); );
assert!(does_contain_matches); assert!(does_contain_matches);