summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2019-01-15 21:47:04 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2019-01-15 21:47:04 +0000
commitbda81243712c7a7e964129729a57b4b5f7b251d6 (patch)
tree7897149273661b3a62f441173ec3d83e59a8ab7c
parentff2905c0a7baa50acb4d0092d0e307458ee5b57d (diff)
downloadrsyarn-bda81243712c7a7e964129729a57b4b5f7b251d6.tar.bz2
Replace try!() with ?
-rw-r--r--src/cli.rs6
-rw-r--r--src/main.rs6
-rw-r--r--src/runner.rs22
-rw-r--r--src/yarn.rs22
4 files changed, 28 insertions, 28 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 5b689dc..dc8c389 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -17,7 +17,7 @@ fn is_number(v: String) -> Result<(), String> {
fn file_exists(v: &OsStr) -> Result<(), OsString> {
let path = Path::new(v);
- let mdata = try!(path.metadata().map_err(|e| e.to_string()));
+ let mdata = path.metadata().map_err(|e| e.to_string())?;
if !mdata.is_file() {
Err("not a file".into())
} else {
@@ -27,7 +27,7 @@ fn file_exists(v: &OsStr) -> Result<(), OsString> {
fn exists_executable(v: &OsStr) -> Result<(), OsString> {
let path = Path::new(v);
- let mdata = try!(path.metadata().map_err(|e| e.to_string()));
+ let mdata = path.metadata().map_err(|e| e.to_string())?;
if !mdata.is_file() {
Err("not a file".into())
} else {
@@ -43,7 +43,7 @@ fn dir_empty_or_not_exists(v: &OsStr) -> Result<(), OsString> {
} else if !path.is_dir() {
Err("not a directory".into())
} else {
- let iter = try!(path.read_dir().map_err(|e| e.to_string()));
+ let iter = path.read_dir().map_err(|e| e.to_string())?;
if iter.count() > 0 {
Err("not empty".into())
} else {
diff --git a/src/main.rs b/src/main.rs
index a7510a8..b55ca18 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -109,17 +109,17 @@ struct YarnJob<'a> {
}
fn run_yarn(args: &opt::YarnArgs) -> err::YarnResult<()> {
- let yf = Arc::new(try!(yarn::YarnFiles::new(&args)));
+ let yf = Arc::new(yarn::YarnFiles::new(&args)?);
let runstart = Instant::now();
- if let Some(msg) = try!(yf.check_implementations()) {
+ if let Some(msg) = yf.check_implementations()? {
if args.verbose {
println!("{}", msg);
}
}
- let (scens, steps) = try!(yf.scenario_count());
+ let (scens, steps) = yf.scenario_count()?;
if scens == 0 || steps == 0 {
return Err("ERROR: Could not parse and link any scenarios!".into());
diff --git a/src/runner.rs b/src/runner.rs
index 17be287..37e2c67 100644
--- a/src/runner.rs
+++ b/src/runner.rs
@@ -149,7 +149,7 @@ impl<'a> YarnRunner<'a> {
}
// Now grab the implementation...
let (ref imp, ref impfile) =
- match try!(self.files.unwrap().find_implementation(line, &self.file.unwrap().source)) {
+ match self.files.unwrap().find_implementation(line, &self.file.unwrap().source)? {
None => {
if self.args.allow_missing {
self.running = false;
@@ -170,22 +170,22 @@ impl<'a> YarnRunner<'a> {
datadir.push("DATADIR");
let mut homedir = datadir.clone();
homedir.push("HOME");
- try!(fs::create_dir_all(&homedir));
+ fs::create_dir_all(&homedir)?;
// Now we have a datadir to use, lets load the script into it...
- let scriptfile_ = try!(Temp::new_file_in(&datadir));
+ let scriptfile_ = Temp::new_file_in(&datadir)?;
{
- let mut scriptfile = try!(File::create(&scriptfile_));
+ let mut scriptfile = File::create(&scriptfile_)?;
for prel in &self.args.prologue {
- try!(scriptfile.write_all(&prel.as_bytes()));
- try!(scriptfile.write("\n".as_bytes()));
+ scriptfile.write_all(&prel.as_bytes())?;
+ scriptfile.write("\n".as_bytes())?;
}
for line in &imp.content {
- try!(scriptfile.write_all(&line.as_bytes()));
+ scriptfile.write_all(&line.as_bytes())?;
}
for epil in &self.args.epilogue {
- try!(scriptfile.write_all(&epil.as_bytes()));
- try!(scriptfile.write("\n".as_bytes()));
+ scriptfile.write_all(&epil.as_bytes())?;
+ scriptfile.write("\n".as_bytes())?;
}
}
// And we're okay, so lets actually run the subprocess...
@@ -193,14 +193,14 @@ impl<'a> YarnRunner<'a> {
cmd.args(&self.args.interp_args)
.arg(scriptfile_.to_path_buf())
.env_clear()
- .env("PATH", try!(env::var("PATH")))
+ .env("PATH", env::var("PATH")?)
.env("TERM", "dumb")
.env("SHELL", "/bin/sh")
.env("LC_ALL", "C")
.env("USER", "tomjon")
.env("LOGNAME", "tomjon")
.env("DATADIR", &datadir)
- .env("SRCDIR", try!(env::current_dir()))
+ .env("SRCDIR", env::current_dir()?)
.env("HOME", homedir);
for &(ref key, ref val) in &self.args.env {
cmd.env(key, val);
diff --git a/src/yarn.rs b/src/yarn.rs
index e2753bc..38410aa 100644
--- a/src/yarn.rs
+++ b/src/yarn.rs
@@ -89,7 +89,7 @@ impl YarnImplements {
fn new(cmd: YarnCommand, hdr: String, loc: usize) -> YarnResult<YarnImplements> {
Ok(YarnImplements {
cmd: cmd,
- matcher: try!(Regex::new(&hdr)),
+ matcher: Regex::new(&hdr)?,
content: Vec::new(),
loc: loc,
})
@@ -168,8 +168,8 @@ impl YarnSource {
fn new(file: &String) -> YarnResult<YarnSource> {
let mut text = String::new();
{
- let mut f = try!(File::open(file));
- try!(f.read_to_string(&mut text));
+ let mut f = File::open(file)?;
+ f.read_to_string(&mut text)?;
}
Ok(YarnSource {
file: file.clone(),
@@ -230,7 +230,7 @@ pub struct YarnFile {
impl YarnFile {
fn new(file: &String) -> YarnResult<YarnFile> {
- let source = try!(YarnSource::new(file));
+ let source = YarnSource::new(file)?;
let mut blocks: Vec<(String, Vec<(String, usize)>)> = Vec::new();
{
let mut parser = source.parser();
@@ -484,7 +484,7 @@ impl<'a> YarnFiles<'a> {
args: args,
};
for f in &args.yarns {
- ret.yarnfiles.push(try!(YarnFile::new(&f)));
+ ret.yarnfiles.push(YarnFile::new(&f)?);
}
Ok(ret)
}
@@ -505,12 +505,12 @@ impl<'a> YarnFiles<'a> {
Ok(None)
} else if imps.len() == 0 {
Err(format!("'{}' at {} matches no implementation",
- try!(ssrc.line(ssrc.linenum(sline.loc))).trim(),
+ ssrc.line(ssrc.linenum(sline.loc))?.trim(),
ssrc.format_location(sline.loc))
.into())
} else if imps.len() > 1 {
let mut msg = format!("'{}' at {} matches implementations:",
- try!(ssrc.line(ssrc.linenum(sline.loc))),
+ ssrc.line(ssrc.linenum(sline.loc))?,
ssrc.format_location(sline.loc));
let mut comma = false;
for &(imp, src) in &imps {
@@ -518,7 +518,7 @@ impl<'a> YarnFiles<'a> {
msg.push(',');
}
msg.push_str(&format!(" '{}' at {}",
- try!(src.line(src.linenum(imp.loc))).trim(),
+ src.line(src.linenum(imp.loc))?.trim(),
src.format_location(imp.loc)));
comma = true;
}
@@ -533,7 +533,7 @@ impl<'a> YarnFiles<'a> {
for f in &self.yarnfiles {
for scen in &f.scenarios {
for sline in &scen.lines {
- if let Some((optimpl, _)) = try!(self.find_implementation(&sline, &f.source)) {
+ if let Some((optimpl, _)) = self.find_implementation(&sline, &f.source)? {
implset.insert(optimpl);
}
}
@@ -546,7 +546,7 @@ impl<'a> YarnFiles<'a> {
if !implset.contains(maybeimpl) {
msg.push_str(
&format!("\n '{}' at {}",
- try!(f.source.line(f.source.linenum(maybeimpl.loc))).trim(),
+ f.source.line(f.source.linenum(maybeimpl.loc))?.trim(),
f.source.format_location(maybeimpl.loc)));
badimpls += 1;
}
@@ -567,7 +567,7 @@ impl<'a> YarnFiles<'a> {
continue 'scen;
}
for sline in &scen.lines {
- match try!(self.find_implementation(&sline, &f.source)) {
+ match self.find_implementation(&sline, &f.source)? {
None => continue 'scen,
_ => {}
}