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