Browse Source

refactoring: use String instead of &str in interpret

main
fdai7451 2 years ago
parent
commit
2ed92df374
  1. 4
      src/execute.rs
  2. 2
      src/main.rs

4
src/execute.rs

@ -5,11 +5,11 @@ use crate::builtins::{execute_builtin, is_builtin};
use crate::error::ShellError; use crate::error::ShellError;
use crate::parse::parse_line; use crate::parse::parse_line;
pub fn interpret(line: &str) -> Result<(), ShellError> {
pub fn interpret(line: String) -> Result<(), ShellError> {
if line.is_empty() { if line.is_empty() {
return Err(ShellError::EmptyLine); return Err(ShellError::EmptyLine);
} }
let (keyword, args) = parse_line(line)?;
let (keyword, args) = parse_line(&line)?;
if is_builtin(keyword) { if is_builtin(keyword) {
execute_builtin(keyword, args)?; execute_builtin(keyword, args)?;

2
src/main.rs

@ -20,7 +20,7 @@ fn main() -> Result<()> {
let readline = rl.readline(&prompt.get_prompt()); let readline = rl.readline(&prompt.get_prompt());
match readline { match readline {
Ok(line) => match interpret(&line) {
Ok(line) => match interpret(line) {
Ok(_) => {} Ok(_) => {}
Err(ShellError::EmptyLine) => { Err(ShellError::EmptyLine) => {
continue; continue;

Loading…
Cancel
Save