1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-01-18 20:01:48 +01:00

Get dynamic segment by name instead of iterator

This commit is contained in:
Nikolay Kim 2019-04-03 21:40:21 -07:00
parent 5e8ae210f7
commit 629ed05f82
3 changed files with 18 additions and 14 deletions

View File

@ -1,5 +1,9 @@
# Changes # Changes
## [0.1.1] - 2019-04-03
* Get dynamic segment by name instead of iterator.
## [0.1.0] - 2019-03-09 ## [0.1.0] - 2019-03-09
* Initial release * Initial release

View File

@ -1,16 +1,16 @@
[package] [package]
name = "actix-router" name = "actix-router"
version = "0.1.0" version = "0.1.1"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"] authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Path router" description = "Path router"
keywords = ["actix"] keywords = ["actix"]
homepage = "https://actix.rs" homepage = "https://actix.rs"
repository = "https://github.com/actix/actix-net.git" repository = "https://github.com/actix/actix-net.git"
documentation = "https://actix.rs/api/actix-net/stable/actix_router/" documentation = "https://docs.rs/actix-router/"
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"] exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"]
edition = "2018" edition = "2018"
workspace = "../" workspace = ".."
[lib] [lib]
name = "actix_router" name = "actix_router"
@ -23,7 +23,8 @@ default = ["http"]
bytes = "0.4" bytes = "0.4"
regex = "1.0" regex = "1.0"
serde = "1.0.80" serde = "1.0.80"
string = "0.1.3" string = "0.2.0"
log = "0.4"
http = { version="0.1.14", optional=true } http = { version="0.1.14", optional=true }
[dev-dependencies] [dev-dependencies]

View File

@ -196,18 +196,17 @@ impl ResourceDef {
[PathItem::Static(""); MAX_DYNAMIC_SEGMENTS]; [PathItem::Static(""); MAX_DYNAMIC_SEGMENTS];
if let Some(captures) = re.captures(path.path()) { if let Some(captures) = re.captures(path.path()) {
let mut passed = false; for (no, name) in names.iter().enumerate() {
if let Some(m) = captures.name(&name) {
for capture in captures.iter() {
if let Some(ref m) = capture {
if !passed {
passed = true;
continue;
}
segments[idx] = PathItem::Segment(m.start() as u16, m.end() as u16);
idx += 1; idx += 1;
pos = m.end(); pos = m.end();
segments[no] = PathItem::Segment(m.start() as u16, m.end() as u16);
} else {
log::error!(
"Dynamic path match but not all segments found: {}",
name
);
false;
} }
} }
} else { } else {