1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
extern crate regex; use self::regex::Regex; /// Represents a path in HTTP sense (starting from `/`) #[derive(Debug)] pub struct Path { pub matcher: Regex } impl Path { /// Creates a new path. /// /// This method accepts regular expressions so you can /// write something like this: /// /// ```no_run /// use hyper_router::Path; /// Path::new(r"/person/\d+"); /// ``` /// /// Note that you don't have to match beggining and end of the /// path using `^` and `$` - those are inserted for you automatically. pub fn new(path: &str) -> Path { let mut regex = "^".to_string(); regex.push_str(path); regex.push_str("$"); Path { matcher: Regex::new(®ex).unwrap() } } }