Change filename to path for clarity

This commit is contained in:
Jarkko Kuukkanen 2020-03-13 12:07:51 +02:00
parent 8c1c37666d
commit 6c72e3c48b
No known key found for this signature in database
GPG Key ID: 7F6664266DAD7878
3 changed files with 15 additions and 15 deletions

View File

@ -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.

View File

@ -106,26 +106,26 @@ impl<'e> Engine<'e> {
}
/// Compile a file into an AST.
pub fn compile_file(&self, filename: PathBuf) -> Result<AST, EvalAltResult> {
let mut f = File::open(filename.clone())
.map_err(|err| EvalAltResult::ErrorReadingScriptFile(filename.clone(), err))?;
pub fn compile_file(&self, path: PathBuf) -> Result<AST, 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.compile(&contents).map_err(EvalAltResult::ErrorParsing))
}
/// Evaluate a file.
pub fn eval_file<T: Any + Clone>(&mut self, filename: PathBuf) -> Result<T, EvalAltResult> {
let mut f = File::open(filename.clone())
.map_err(|err| EvalAltResult::ErrorReadingScriptFile(filename.clone(), err))?;
pub fn eval_file<T: Any + Clone>(&mut self, path: PathBuf) -> Result<T, 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.eval::<T>(&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))
}

View File

@ -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!(