Skip to content

Commit f8f1ac9

Browse files
committed
add Patterns::is_empty and impl IntoPatterns for Patterns
1 parent 82cd5b8 commit f8f1ac9

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

actix-router/CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Fix a bug in multi-patterns where static patterns are interpreted as regex. [#366]
88
* Introduce `ResourceDef::pattern_iter` to get an iterator over all patterns in a multi-pattern resource. [#373]
99
* Fix segment interpolation leaving `Path` in unintended state after matching. [#368]
10-
* Fix `ResourceDef` `PartialEq` implementation.
10+
* Fix `ResourceDef` `PartialEq` implementation. [#373]
1111
* Re-work `IntoPatterns` trait, adding a `Patterns` enum. [#372]
1212
* Implement `IntoPatterns` for `bytestring::ByteString`. [#372]
1313
* Rename `Path::{len => segment_count}` to be more descriptive of it's purpose. [#370]

actix-router/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ pub enum Patterns {
4949
List(Vec<String>),
5050
}
5151

52+
impl Patterns {
53+
pub fn is_empty(&self) -> bool {
54+
match self {
55+
Patterns::Single(_) => false,
56+
Patterns::List(pats) => pats.is_empty(),
57+
}
58+
}
59+
}
60+
5261
/// Helper trait for type that could be converted to one or more path pattern.
5362
pub trait IntoPatterns {
5463
fn patterns(&self) -> Patterns;
@@ -78,6 +87,12 @@ impl IntoPatterns for bytestring::ByteString {
7887
}
7988
}
8089

90+
impl IntoPatterns for Patterns {
91+
fn patterns(&self) -> Patterns {
92+
self.clone()
93+
}
94+
}
95+
8196
impl<T: AsRef<str>> IntoPatterns for Vec<T> {
8297
fn patterns(&self) -> Patterns {
8398
let mut patterns = self.iter().map(|v| v.as_ref().to_owned());

0 commit comments

Comments
 (0)