From ea7f6b4d37bd75f3e1df4792bc0820690db5231e Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Tue, 28 Aug 2018 16:59:32 -0400 Subject: [PATCH] Pass a string slice around in main.rs We only need to convert it to a String once we're passing it in to compile::compile. --- src/main.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 36c11400e3..194cef3bda 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,9 +50,14 @@ fn main() { } } -fn _run_string(source: &String, source_path: Option) { +fn _run_string(source: &str, source_path: Option) { let mut vm = VirtualMachine::new(); - let code_obj = compile::compile(&mut vm, &source, compile::Mode::Exec, source_path).unwrap(); + let code_obj = compile::compile( + &mut vm, + &source.to_string(), + compile::Mode::Exec, + source_path, + ).unwrap(); debug!("Code object: {:?}", code_obj.borrow()); let builtins = vm.get_builtin_scope(); let vars = vm.context().new_scope(Some(builtins)); // Keep track of local variables @@ -74,7 +79,7 @@ fn run_command(source: &mut String) { _run_string(source, None) } -fn run_script(script_file: &String) { +fn run_script(script_file: &str) { debug!("Running file {}", script_file); // Parse an ast from it: let filepath = Path::new(script_file); @@ -87,8 +92,8 @@ fn run_script(script_file: &String) { } } -fn shell_exec(vm: &mut VirtualMachine, source: &String, scope: PyObjectRef) -> bool { - match compile::compile(vm, source, compile::Mode::Single, None) { +fn shell_exec(vm: &mut VirtualMachine, source: &str, scope: PyObjectRef) -> bool { + match compile::compile(vm, &source.to_string(), compile::Mode::Single, None) { Ok(code) => { match vm.run_code_obj(code, scope.clone()) { Ok(_value) => {