Need to check if an expression matches certain pattern?
1
2
let foo = vec!['1','2'];
assert!(matches!(foo.len(), 0..=1));
The example above checks if len is 0 or 1.
Or
1
2
3
let bar = Some(4);
assert!(matches!(bar, Some(x) if x > 2));
Need to check if an expression matches certain pattern?
1
2
let foo = vec!['1','2'];
assert!(matches!(foo.len(), 0..=1));
The example above checks if len is 0 or 1.
Or
1
2
3
let bar = Some(4);
assert!(matches!(bar, Some(x) if x > 2));
A new version of content is available.