Skip to content

Instantly share code, notes, and snippets.

fn render_docs(source: &Path, dest: &Path) -> Result<(), io::Error> {
let dir_list = try!(read_dir(source)
.map_err(|e| Error::Io(source.to_path_buf(), e)));
for entry_res in dir_list {
let entry = try!(entry_res
.map_err(|e| Error::Io(source.to_path_buf(), e)));
let path = entry.path();
let file = try!(File::open(&path)
.map_err(|e| Error::Io(path.clone(), e)));
for line_res in file.lines() {
enum DocsError {
Io(path: PathBuf, io::Error),
Format(path: PathBuf, lineno: usize, doc::FormatError),
}
enum DocsError {
Io(path: PathBuf, io::Error),
Format(path: PathBuf, lineno: usize, doc::FormatError),
}
enum DocsError {
Io(io::Error),
Format(doc::FormatError),
}
fn render_docs(source: &Path, &dest: &Path) -> Result<(), ErrorType> {
// ... read files at source
// ... write files to dest
Ok(())
}
fn main() {
// .. parse command line
match render_docs(&src, &dst) {
Ok(()) => {}
fn render_docs(source: &Path, dest: &Path) -> Result<(), io::Error> {
for entry_res in try!(read_dir(source)) {
let entry = try!(entry_res);
let file = try!(File::open(&entry.path());
for line_res in file.lines() {
let line = try!(line_res);
// ...
if wrong_syntax_flag {
return Err(io::Error::new(io::ErrorKind::Other,
"Wrong syntax"));
[dependencies.quick-error]
git = "http://github.com/tailhook/quick-error"
branch = "context2"
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>>;
}