1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-24 01:11:07 +01:00

ResourceDef: relax unnecessary bounds (#381)

This commit is contained in:
Ali MJ Al-Nasrawy 2021-08-06 19:45:10 +03:00 committed by GitHub
parent f8f1ac94bc
commit 5379a46a99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -616,13 +616,8 @@ impl ResourceDef {
profile_method!(find_match); profile_method!(find_match);
match &self.pat_type { match &self.pat_type {
PatternType::Static(segment) => { PatternType::Static(segment) if path == segment => Some(segment.len()),
if segment == path { PatternType::Static(_) => None,
Some(segment.len())
} else {
None
}
}
PatternType::Prefix(prefix) if path == prefix => Some(prefix.len()), PatternType::Prefix(prefix) if path == prefix => Some(prefix.len()),
PatternType::Prefix(prefix) if is_strict_prefix(prefix, path) => Some(prefix.len()), PatternType::Prefix(prefix) if is_strict_prefix(prefix, path) => Some(prefix.len()),
@ -660,7 +655,7 @@ impl ResourceDef {
/// ``` /// ```
pub fn capture_match_info<T: ResourcePath>(&self, path: &mut Path<T>) -> bool { pub fn capture_match_info<T: ResourcePath>(&self, path: &mut Path<T>) -> bool {
profile_method!(is_path_match); profile_method!(is_path_match);
self.capture_match_info_fn(path, &|_, _| true, &None::<()>) self.capture_match_info_fn(path, |_, _| true, ())
} }
/// Collects dynamic segment values into `resource` after matching paths and executing /// Collects dynamic segment values into `resource` after matching paths and executing
@ -683,7 +678,7 @@ impl ResourceDef {
/// resource.capture_match_info_fn( /// resource.capture_match_info_fn(
/// path, /// path,
/// // when env var is not set, reject when path contains "admin" /// // when env var is not set, reject when path contains "admin"
/// &|res, admin_allowed| !res.path().contains("admin"), /// |res, admin_allowed| !res.path().contains("admin"),
/// &admin_allowed /// &admin_allowed
/// ) /// )
/// } /// }
@ -704,13 +699,13 @@ impl ResourceDef {
pub fn capture_match_info_fn<R, T, F, U>( pub fn capture_match_info_fn<R, T, F, U>(
&self, &self,
resource: &mut R, resource: &mut R,
check_fn: &F, check_fn: F,
user_data: &Option<U>, user_data: U,
) -> bool ) -> bool
where where
R: Resource<T>, R: Resource<T>,
T: ResourcePath, T: ResourcePath,
F: Fn(&R, &Option<U>) -> bool, F: FnOnce(&R, U) -> bool,
{ {
profile_method!(is_path_match_fn); profile_method!(is_path_match_fn);