1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-30 10:42:55 +01:00

document Path::unprocessed panic

This commit is contained in:
Rob Ede 2022-01-19 18:33:23 +00:00
parent cb5d9a7e64
commit 3dd98c308c
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
3 changed files with 20 additions and 7 deletions

View File

@ -49,7 +49,7 @@ impl<T: ResourcePath> Path<T> {
&mut self.path
}
/// Path.
/// Returns unprocessed part of the path.
#[inline]
pub fn path(&self) -> &str {
profile_method!(path);
@ -63,9 +63,21 @@ impl<T: ResourcePath> Path<T> {
}
}
/// 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<T: ResourcePath> Path<T> {
/// Reset state.
#[inline]
pub fn reset(&mut self) {
profile_method!(reset);
self.skip = 0;
self.segments.clear();
}
@ -81,6 +95,7 @@ impl<T: ResourcePath> Path<T> {
/// 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<T: ResourcePath> Path<T> {
name: impl Into<Cow<'static, str>>,
value: impl Into<Cow<'static, str>>,
) {
profile_method!(add_static);
self.segments
.push((name.into(), PathItem::Static(value.into())));
}
@ -136,11 +153,6 @@ impl<T: ResourcePath> Path<T> {
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.

View File

@ -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());

View File

@ -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.