This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
quick_error! { | |
#[derive(Debug)] | |
pub enum Error { | |
Io(err: io::Error, path: PathBuf) { | |
display("could not read file {:?}: {}", path, err) | |
context(path: &'a Path, err: io::Error) | |
-> (err, path.to_path_buf()) | |
} | |
// ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub struct Context<X, E>(pub X, pub E); | |
impl<T, E> ResultExt<T, E> for Result<T, E> { | |
fn context<X>(self, x: X) -> Result<T, Context<X, E>> { | |
self.map_err(|e| Context(x, e)) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub trait ResultExt<T, E> { | |
fn context<X>(self, x: X) -> Result<T, Context<X, E>>; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Error { | |
Io(io::Error), | |
Parse(ParseIntError), | |
} | |
// ... | |
try!(File::open(fname) | |
.and_then(|mut f| f.read_to_string(&mut buf)) | |
.map_err(|e| Error::Io(e, fname.to_path_buf()))); | |
let x: u64 = try!(buf.parse() | |
.map_err(|e| Error::Parse(e, fname.to_path_buf()))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use(quick_error)] extern crate quick_error; | |
use std::io::{self, stderr, Read, Write}; | |
use std::fs::File; | |
use std::env; | |
use std::num::ParseIntError; | |
use std::path::{Path, PathBuf}; | |
quick_error! { | |
#[derive(Debug)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use(quick_error)] extern crate quick_error; | |
use std::io::{self, stderr, Read, Write}; | |
use std::fs::File; | |
use std::env; | |
use std::num::ParseIntError; | |
use std::path::{Path, PathBuf}; | |
use quick_error::ResultExt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use(quick_error)] extern crate quick_error; | |
use std::io::{self, stderr, Read, Write}; | |
use std::fs::File; | |
use std::env; | |
use std::num::ParseIntError; | |
use std::path::{Path, PathBuf}; | |
use quick_error::ResultExt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- examples/serve.rs 2016-03-29 00:14:50.712643740 +0300 | |
+++ examples/serve_sendfile.rs 2016-04-05 00:13:24.651021841 +0300 | |
@@ -14,7 +14,8 @@ | |
enum Http { | |
ReadHeaders, | |
- SendResponse, | |
+ SendingFile { offset: u64 }, | |
+ BodySent, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> ~/wrk -t 2 -c 20 -d 60 http://hostname:3000 --latency | |
Running 1m test @ http://hostname:3000 | |
2 threads and 20 connections | |
Thread Stats Avg Stdev Max +/- Stdev | |
Latency 268.13us 84.07us 4.46ms 95.35% | |
Req/Sec 37.74k 3.65k 68.62k 90.92% | |
Latency Distribution | |
50% 248.00us | |
75% 291.00us | |
90% 300.00us |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> ~/wrk -t 2 -c 20 -d 60 http://hostname:3000 --latency | |
Running 1m test @ http://hostname:3000 | |
2 threads and 20 connections | |
Thread Stats Avg Stdev Max +/- Stdev | |
Latency 451.75us 73.89us 2.42ms 78.56% | |
Req/Sec 18.19k 1.54k 28.56k 83.44% | |
Latency Distribution | |
50% 441.00us | |
75% 488.00us | |
90% 545.00us |