Starting to add documentation
Getty Ritter
8 years ago
1 | 1 |
extern crate hyper;
|
2 | 2 |
extern crate std;
|
3 | 3 |
|
| 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
|
4 | 7 |
#[derive(Debug)]
|
5 | 8 |
pub enum AloysError {
|
6 | 9 |
IOError(std::io::Error),
|
7 | 7 |
use std::io::prelude::Read;
|
8 | 8 |
use std::path::Path;
|
9 | 9 |
|
| 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 |
/// ```
|
10 | 24 |
pub fn with_file<A, F>(path: &Path, default: A, callback: F) -> A
|
11 | 25 |
where F: FnOnce(String) -> A + 'static {
|
12 | 26 |
match File::open(path) {
|
135 | 135 |
fn run(&self, req: &Request, res: Response<Fresh>) {
|
136 | 136 |
match self {
|
137 | 137 |
&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());
|
139 | 141 |
},
|
140 | 142 |
&Delegate::Defer(ref rts) => {
|
141 | 143 |
rts.dispatch(req, res);
|
| 1 |
/// Find out whether the `spec_str` matches the `string_str`.
|
| 2 |
/// The former can contain the wildcard character `*`.
|
1 | 3 |
pub fn do_match(spec_str: &str, string_str: &str) -> bool {
|
2 | 4 |
let spec = spec_str.as_bytes();
|
3 | 5 |
let string = string_str.as_bytes();
|