mirror of
https://github.com/fafhrd91/actix-net
synced 2025-01-18 20:01:48 +01:00
add Patterns::is_empty and impl IntoPatterns for Patterns
This commit is contained in:
parent
82cd5b8290
commit
f8f1ac94bc
@ -7,7 +7,7 @@
|
|||||||
* Fix a bug in multi-patterns where static patterns are interpreted as regex. [#366]
|
* Fix a bug in multi-patterns where static patterns are interpreted as regex. [#366]
|
||||||
* Introduce `ResourceDef::pattern_iter` to get an iterator over all patterns in a multi-pattern resource. [#373]
|
* Introduce `ResourceDef::pattern_iter` to get an iterator over all patterns in a multi-pattern resource. [#373]
|
||||||
* Fix segment interpolation leaving `Path` in unintended state after matching. [#368]
|
* Fix segment interpolation leaving `Path` in unintended state after matching. [#368]
|
||||||
* Fix `ResourceDef` `PartialEq` implementation.
|
* Fix `ResourceDef` `PartialEq` implementation. [#373]
|
||||||
* Re-work `IntoPatterns` trait, adding a `Patterns` enum. [#372]
|
* Re-work `IntoPatterns` trait, adding a `Patterns` enum. [#372]
|
||||||
* Implement `IntoPatterns` for `bytestring::ByteString`. [#372]
|
* Implement `IntoPatterns` for `bytestring::ByteString`. [#372]
|
||||||
* Rename `Path::{len => segment_count}` to be more descriptive of it's purpose. [#370]
|
* Rename `Path::{len => segment_count}` to be more descriptive of it's purpose. [#370]
|
||||||
|
@ -49,6 +49,15 @@ pub enum Patterns {
|
|||||||
List(Vec<String>),
|
List(Vec<String>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Patterns {
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Patterns::Single(_) => false,
|
||||||
|
Patterns::List(pats) => pats.is_empty(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Helper trait for type that could be converted to one or more path pattern.
|
/// Helper trait for type that could be converted to one or more path pattern.
|
||||||
pub trait IntoPatterns {
|
pub trait IntoPatterns {
|
||||||
fn patterns(&self) -> Patterns;
|
fn patterns(&self) -> Patterns;
|
||||||
@ -78,6 +87,12 @@ impl IntoPatterns for bytestring::ByteString {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl IntoPatterns for Patterns {
|
||||||
|
fn patterns(&self) -> Patterns {
|
||||||
|
self.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: AsRef<str>> IntoPatterns for Vec<T> {
|
impl<T: AsRef<str>> IntoPatterns for Vec<T> {
|
||||||
fn patterns(&self) -> Patterns {
|
fn patterns(&self) -> Patterns {
|
||||||
let mut patterns = self.iter().map(|v| v.as_ref().to_owned());
|
let mut patterns = self.iter().map(|v| v.as_ref().to_owned());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user