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::parse::parse_line;
pub fn interpret(line: &str) -> Result<(), ShellError> {
pub fn interpret(line: String) -> Result<(), ShellError> {
if line.is_empty() {
return Err(ShellError::EmptyLine);
}
let (keyword, args) = parse_line(line)?;
let (keyword, args) = parse_line(&line)?;
if is_builtin(keyword) {
execute_builtin(keyword, args)?;

2
src/main.rs

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

Loading…
Cancel
Save