mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 01:32:57 +01:00
simplify has_prefixed_route()
This commit is contained in:
parent
bce05e4fcb
commit
b7a3fce17b
@ -1,7 +1,6 @@
|
||||
use std::cmp::min;
|
||||
use std::collections::HashMap;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
|
||||
use regex::{escape, Regex};
|
||||
@ -159,19 +158,11 @@ impl ResourceInfo {
|
||||
/// It will not match against prefix in case it's not given. For example for `/name`
|
||||
/// with a `/test` prefix would return `false`
|
||||
pub fn has_prefixed_route(&self, path: &str) -> bool {
|
||||
if self.prefix == 0 {
|
||||
return self.has_route(path);
|
||||
let prefix = self.prefix as usize;
|
||||
if prefix >= path.len() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let path_matcher = Path::new(if path.is_empty() { "/" } else { path });
|
||||
let router_prefix = Path::new(&path[..(self.prefix as usize)]);
|
||||
if let Ok(p) = path_matcher.strip_prefix(router_prefix) {
|
||||
if let Some(p_str) = p.to_str() {
|
||||
return self.has_route(&format!("/{}", p_str));
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
self.has_route(&path[prefix..])
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user