diff --git a/README.md b/README.md index 71f33028..16e40b54 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ use rhai::Engine; let mut engine = Engine::new(); -let ast = engine.compile_file("hello_world.rhai").unwrap(); +let ast = engine.compile_file("hello_world.rhai".into()).unwrap(); ``` Rhai also allows you to work _backwards_ from the other direction - i.e. calling a Rhai-scripted function from Rust. diff --git a/src/api.rs b/src/api.rs index 29ef1472..d3fc6402 100644 --- a/src/api.rs +++ b/src/api.rs @@ -106,26 +106,26 @@ impl<'e> Engine<'e> { } /// Compile a file into an AST. - pub fn compile_file(&self, filename: PathBuf) -> Result { - let mut f = File::open(filename.clone()) - .map_err(|err| EvalAltResult::ErrorReadingScriptFile(filename.clone(), err))?; + pub fn compile_file(&self, path: PathBuf) -> Result { + let mut f = File::open(path.clone()) + .map_err(|err| EvalAltResult::ErrorReadingScriptFile(path.clone(), err))?; let mut contents = String::new(); f.read_to_string(&mut contents) - .map_err(|err| EvalAltResult::ErrorReadingScriptFile(filename.clone(), err)) + .map_err(|err| EvalAltResult::ErrorReadingScriptFile(path.clone(), err)) .and_then(|_| self.compile(&contents).map_err(EvalAltResult::ErrorParsing)) } /// Evaluate a file. - pub fn eval_file(&mut self, filename: PathBuf) -> Result { - let mut f = File::open(filename.clone()) - .map_err(|err| EvalAltResult::ErrorReadingScriptFile(filename.clone(), err))?; + pub fn eval_file(&mut self, path: PathBuf) -> Result { + let mut f = File::open(path.clone()) + .map_err(|err| EvalAltResult::ErrorReadingScriptFile(path.clone(), err))?; let mut contents = String::new(); f.read_to_string(&mut contents) - .map_err(|err| EvalAltResult::ErrorReadingScriptFile(filename.clone(), err)) + .map_err(|err| EvalAltResult::ErrorReadingScriptFile(path.clone(), err)) .and_then(|_| self.eval::(&contents)) } @@ -206,14 +206,14 @@ impl<'e> Engine<'e> { /// Evaluate a file, but throw away the result and only return error (if any). /// Useful for when you don't need the result, but still need to keep track of possible errors. - pub fn consume_file(&mut self, filename: PathBuf) -> Result<(), EvalAltResult> { - let mut f = File::open(filename.clone()) - .map_err(|err| EvalAltResult::ErrorReadingScriptFile(filename.clone(), err))?; + pub fn consume_file(&mut self, path: PathBuf) -> Result<(), EvalAltResult> { + let mut f = File::open(path.clone()) + .map_err(|err| EvalAltResult::ErrorReadingScriptFile(path.clone(), err))?; let mut contents = String::new(); f.read_to_string(&mut contents) - .map_err(|err| EvalAltResult::ErrorReadingScriptFile(filename.clone(), err)) + .map_err(|err| EvalAltResult::ErrorReadingScriptFile(path.clone(), err)) .and_then(|_| self.consume(&contents)) } diff --git a/src/result.rs b/src/result.rs index a90abce1..16569a48 100644 --- a/src/result.rs +++ b/src/result.rs @@ -124,8 +124,8 @@ impl fmt::Display for EvalAltResult { } Self::LoopBreak => write!(f, "{}", desc), Self::Return(_, pos) => write!(f, "{} ({})", desc, pos), - Self::ErrorReadingScriptFile(filename, err) => { - write!(f, "{} '{}': {}", desc, filename.display(), err) + Self::ErrorReadingScriptFile(path, err) => { + write!(f, "{} '{}': {}", desc, path.display(), err) } Self::ErrorParsing(p) => write!(f, "Syntax error: {}", p), Self::ErrorFunctionArgsMismatch(fun, need, n, pos) => write!(