Return 'Path' from 'Catcher::base()'.

This commit is contained in:
Sergio Benitez 2023-04-10 13:42:20 -07:00
parent c13a6c6a79
commit 0c80f7d9e0
1 changed files with 8 additions and 7 deletions

View File

@ -1,6 +1,7 @@
use std::fmt; use std::fmt;
use std::io::Cursor; use std::io::Cursor;
use crate::http::uri::Path;
use crate::response::Response; use crate::response::Response;
use crate::request::Request; use crate::request::Request;
use crate::http::{Status, ContentType, uri}; use crate::http::{Status, ContentType, uri};
@ -198,13 +199,13 @@ impl Catcher {
/// } /// }
/// ///
/// let catcher = Catcher::new(404, handle_404); /// let catcher = Catcher::new(404, handle_404);
/// assert_eq!(catcher.base().path(), "/"); /// assert_eq!(catcher.base(), "/");
/// ///
/// let catcher = catcher.map_base(|base| format!("/foo/bar/{}", base)).unwrap(); /// let catcher = catcher.map_base(|base| format!("/foo/bar/{}", base)).unwrap();
/// assert_eq!(catcher.base().path(), "/foo/bar"); /// assert_eq!(catcher.base(), "/foo/bar");
/// ``` /// ```
pub fn base(&self) -> &uri::Origin<'_> { pub fn base(&self) -> Path<'_> {
&self.base self.base.path()
} }
/// Maps the `base` of this catcher using `mapper`, returning a new /// Maps the `base` of this catcher using `mapper`, returning a new
@ -229,13 +230,13 @@ impl Catcher {
/// } /// }
/// ///
/// let catcher = Catcher::new(404, handle_404); /// let catcher = Catcher::new(404, handle_404);
/// assert_eq!(catcher.base().path(), "/"); /// assert_eq!(catcher.base(), "/");
/// ///
/// let catcher = catcher.map_base(|_| format!("/bar")).unwrap(); /// let catcher = catcher.map_base(|_| format!("/bar")).unwrap();
/// assert_eq!(catcher.base().path(), "/bar"); /// assert_eq!(catcher.base(), "/bar");
/// ///
/// let catcher = catcher.map_base(|base| format!("/foo{}", base)).unwrap(); /// let catcher = catcher.map_base(|base| format!("/foo{}", base)).unwrap();
/// assert_eq!(catcher.base().path(), "/foo/bar"); /// assert_eq!(catcher.base(), "/foo/bar");
/// ///
/// let catcher = catcher.map_base(|base| format!("/foo ? {}", base)); /// let catcher = catcher.map_base(|base| format!("/foo ? {}", base));
/// assert!(catcher.is_err()); /// assert!(catcher.is_err());