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
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() { |
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 DocsError { | |
Io(path: PathBuf, io::Error), | |
Format(path: PathBuf, lineno: usize, doc::FormatError), | |
} |
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 DocsError { | |
Io(path: PathBuf, io::Error), | |
Format(path: PathBuf, lineno: usize, doc::FormatError), | |
} |
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 DocsError { | |
Io(io::Error), | |
Format(doc::FormatError), | |
} |
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
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(()) => {} |
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
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")); |
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
[dependencies.quick-error] | |
git = "http://github.com/tailhook/quick-error" | |
branch = "context2" |
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>>; | |
} |