Skip to content

Instantly share code, notes, and snippets.

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())
}
// ...
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))
}
}
pub trait ResultExt<T, E> {
fn context<X>(self, x: X) -> Result<T, Context<X, E>>;
}
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())));
#[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)]
#[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;
#[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;
--- 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,
}
> ~/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
> ~/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