gdritter repos httputils / 4c37c7d
Starting to add documentation Getty Ritter 8 years ago
4 changed file(s) with 22 addition(s) and 1 deletion(s). Collapse all Expand all
11 extern crate hyper;
22 extern crate std;
33
4 /// An `AloysError` is one of the errors that can occur in
5 /// the course of running an Aloys server. This might be
6 /// an `IOError` from
47 #[derive(Debug)]
58 pub enum AloysError {
69 IOError(std::io::Error),
77 use std::io::prelude::Read;
88 use std::path::Path;
99
10 /// Open up a file and call the callback F on it, producing a
11 /// value of type A. If the file does not exist, then return
12 /// the default value.
13 ///
14 /// # Examples
15 ///
16 /// ```
17 /// let str = with_file("file_one",
18 /// "default".to_string(),
19 /// |str| str);
20 /// let num = with_file("file_two",
21 /// 42,
22 /// |str| str.parse::<u32>());
23 /// ```
1024 pub fn with_file<A, F>(path: &Path, default: A, callback: F) -> A
1125 where F: FnOnce(String) -> A + 'static {
1226 match File::open(path) {
135135 fn run(&self, req: &Request, res: Response<Fresh>) {
136136 match self {
137137 &Delegate::Forward(ref fwd) => {
138 let _ = res.send(format!("[forward to {:?}:{:?}]", fwd.domn, fwd.port).as_bytes());
138 let _ = res.send(format!("[forward to {:?}:{:?}]",
139 fwd.domn,
140 fwd.port).as_bytes());
139141 },
140142 &Delegate::Defer(ref rts) => {
141143 rts.dispatch(req, res);
1 /// Find out whether the `spec_str` matches the `string_str`.
2 /// The former can contain the wildcard character `*`.
13 pub fn do_match(spec_str: &str, string_str: &str) -> bool {
24 let spec = spec_str.as_bytes();
35 let string = string_str.as_bytes();