Use ErrFromStr convenience extension

This commit is contained in:
Matthias Beyer 2018-02-12 21:25:33 +01:00
parent 5b07baddf8
commit 6b0930adec

View file

@ -44,7 +44,6 @@ extern crate libimagerror;
extern crate libimagrt; extern crate libimagrt;
extern crate libimagstore; extern crate libimagstore;
use std::error::Error;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::io::Write; use std::io::Write;
use std::path::PathBuf; use std::path::PathBuf;
@ -55,6 +54,7 @@ use handlebars::Handlebars;
use toml_query::read::TomlValueReadTypeExt; use toml_query::read::TomlValueReadTypeExt;
use libimagrt::setup::generate_runtime_setup; use libimagrt::setup::generate_runtime_setup;
use libimagerror::str::ErrFromStr;
use libimagerror::trace::MapErrTrace; use libimagerror::trace::MapErrTrace;
use libimagentryview::builtin::stdout::StdoutViewer; use libimagentryview::builtin::stdout::StdoutViewer;
use libimagentryview::viewer::Viewer; use libimagentryview::viewer::Viewer;
@ -108,29 +108,29 @@ fn main() {
let _ = handlebars let _ = handlebars
.register_template_string("template", viewer_template) .register_template_string("template", viewer_template)
.map_err(|e| format!("{}", e.description())) .err_from_str()
.map_err(VE::from) .map_err(VE::from)
.map_err_trace_exit_unwrap(1); .map_err_trace_exit_unwrap(1);
let file = { let file = {
let mut tmpfile = tempfile::NamedTempFile::new() let mut tmpfile = tempfile::NamedTempFile::new()
.map_err(|e| format!("{}", e.description())) .err_from_str()
.map_err(VE::from) .map_err(VE::from)
.map_err_trace_exit_unwrap(1); .map_err_trace_exit_unwrap(1);
if view_header { if view_header {
let hdr = toml::ser::to_string_pretty(entry.get_header()) let hdr = toml::ser::to_string_pretty(entry.get_header())
.map_err(|e| format!("{}", e.description())) .err_from_str()
.map_err(VE::from) .map_err(VE::from)
.map_err_trace_exit_unwrap(1); .map_err_trace_exit_unwrap(1);
let _ = tmpfile.write(format!("---\n{}---\n", hdr).as_bytes()) let _ = tmpfile.write(format!("---\n{}---\n", hdr).as_bytes())
.map_err(|e| format!("{}", e.description())) .err_from_str()
.map_err(VE::from) .map_err(VE::from)
.map_err_trace_exit_unwrap(1); .map_err_trace_exit_unwrap(1);
} }
if !hide_content { if !hide_content {
let _ = tmpfile.write(entry.get_content().as_bytes()) let _ = tmpfile.write(entry.get_content().as_bytes())
.map_err(|e| format!("{}", e.description())) .err_from_str()
.map_err(VE::from) .map_err(VE::from)
.map_err_trace_exit_unwrap(1); .map_err_trace_exit_unwrap(1);
} }
@ -151,7 +151,7 @@ fn main() {
let call = handlebars let call = handlebars
.render("template", &data) .render("template", &data)
.map_err(|e| format!("{}", e.description())) .err_from_str()
.map_err(VE::from) .map_err(VE::from)
.map_err_trace_exit_unwrap(1); .map_err_trace_exit_unwrap(1);
let mut elems = call.split_whitespace(); let mut elems = call.split_whitespace();
@ -170,7 +170,7 @@ fn main() {
if !command if !command
.status() .status()
.map_err(|e| format!("{}", e.description())) .err_from_str()
.map_err(VE::from) .map_err(VE::from)
.map_err_trace_exit_unwrap(1) .map_err_trace_exit_unwrap(1)
.success() .success()