diff --git a/actix-router/src/path.rs b/actix-router/src/path.rs index fc7bb16ac..f8667ad89 100644 --- a/actix-router/src/path.rs +++ b/actix-router/src/path.rs @@ -49,7 +49,7 @@ impl Path { &mut self.path } - /// Path. + /// Returns unprocessed part of the path. #[inline] pub fn path(&self) -> &str { profile_method!(path); @@ -63,9 +63,21 @@ impl Path { } } + /// Returns unprocessed part of the path. + /// + /// # Panics + /// Unlike [`path`](Self::path), this will panic if `skip` indexes further than the path length. + #[inline] + pub fn unprocessed(&self) -> &str { + profile_method!(unprocessed); + &self.path.path()[(self.skip as usize)..] + } + /// Set new path. #[inline] pub fn set(&mut self, path: T) { + profile_method!(set); + self.skip = 0; self.path = path; self.segments.clear(); @@ -74,6 +86,8 @@ impl Path { /// Reset state. #[inline] pub fn reset(&mut self) { + profile_method!(reset); + self.skip = 0; self.segments.clear(); } @@ -81,6 +95,7 @@ impl Path { /// Skip first `n` chars in path. #[inline] pub fn skip(&mut self, n: u16) { + profile_method!(skip); self.skip += n; } @@ -102,6 +117,8 @@ impl Path { name: impl Into>, value: impl Into>, ) { + profile_method!(add_static); + self.segments .push((name.into(), PathItem::Static(value.into()))); } @@ -136,11 +153,6 @@ impl Path { None } - /// Get unprocessed part of the path - pub fn unprocessed(&self) -> &str { - &self.path.path()[(self.skip as usize)..] - } - /// Get matched parameter by name. /// /// If keyed parameter is not available empty string is used as default value. diff --git a/actix-router/src/router.rs b/actix-router/src/router.rs index 47940708e..4652ef678 100644 --- a/actix-router/src/router.rs +++ b/actix-router/src/router.rs @@ -256,6 +256,7 @@ mod tests { router.path("/name/{val}", 11); let mut router = router.finish(); + // test skip beyond path length let mut path = Path::new("/name"); path.skip(6); assert!(router.recognize_mut(&mut path).is_none()); diff --git a/src/request.rs b/src/request.rs index bcab79205..d721f2ac7 100644 --- a/src/request.rs +++ b/src/request.rs @@ -208,7 +208,7 @@ impl HttpRequest { self.resource_map().url_for(self, name, elements) } - /// Generate url for named resource + /// Generate URL for named resource /// /// This method is similar to `HttpRequest::url_for()` but it can be used /// for urls that do not contain variable parts.