mirror of
https://github.com/actix/actix-web.git
synced 2024-11-22 09:31:10 +00:00
document Path::unprocessed panic
This commit is contained in:
parent
cb5d9a7e64
commit
3dd98c308c
3 changed files with 20 additions and 7 deletions
|
@ -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.
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue