/// Parses Commands from the REPL. If Meta, executes on REPL environment,
/// otherwise executes them on the Storage Engine.
Parses Commands from the REPL. If Meta, executes on REPL environment,
otherwise executes them on the Storage Engine.
Parses Commands from the REPL . If Meta executes on REPL environment otherwise executes them on the Storage Engine .
async fn parse_input(&mut self) {
        // Meta commands start with `.`.
        if self.cmd.starts_with(".") {
            match MetaCmdResult::run(&self.cmd) {
                MetaCmdResult::Unrecognized => println!("db: meta command not found: {}", self.cmd),
                MetaCmdResult::Success => {}
            }
        } else {
            let st = Statement::prep(&self.cmd);
            let key = st.key.unwrap_or("".to_string());
            // If type of statement is legit, execute, else fail.
            match match st.stype {
                StatementType::Set => match self
                    .store
                    .set(Request::new(KeyValue {
                        key: key.as_bytes().to_vec(),
                        value: st.value.unwrap().as_bytes().to_vec(),
                    }))
                    .await
                {
                    Ok(_) => ExecResult::Success,
                    Err(e) => {
                        eprintln!("{}", e.message());
                        ExecResult::Failed
                    }
                },
                StatementType::Get => match self
                    .store
                    .get(Request::new(Byte {
                        body: key.as_bytes().to_vec(),
                    }))
                    .await
                {
                    Ok(res) => {
                        println!("{}", String::from_utf8(res.into_inner().body).unwrap());
                        ExecResult::Success
                    }
                    Err(e) => {
                        // If the key doesn't exist, get() explicitly returns this,
                        // so print the desired Error message.
                        eprintln!("{}", e.message());
                        ExecResult::Failed
                    }
                },
                StatementType::Del => match self
                    .store
                    .del(Request::new(Byte {
                        body: key.as_bytes().to_vec(),
                    }))
                    .await
                {
                    Ok(_) => ExecResult::Success,
                    Err(e) => {
                        eprintln!("{}", e.message());
                        ExecResult::Failed
                    }
                },
                StatementType::Unk => {
                    eprintln!("db: command not found: {}", self.cmd);
                    ExecResult::Failed
                }
                StatementType::Fail => ExecResult::Failed,
            } {
                ExecResult::Failed => eprintln!("Command Execution Failed."),
                ExecResult::Success => println!("Success: OK"),
            }
        }
    }
async fn parse_input ( & mut self ) { // Meta commands start with `.`. if self . cmd . starts_with ( " " ) { match MetaCmdResult :: run ( & self . cmd ) { MetaCmdResult :: Unrecognized => println ! ( " " self cmd ) , MetaCmdResult :: Success => { } } } else { let st = Statement :: prep ( & self . cmd ) ; let key = st . key . unwrap_or ( " " . to_string ( ) ) ; // If type of statement is legit, execute, else fail. match match st . stype { StatementType :: Set => match self . store . set ( Request :: new ( KeyValue { key : key . as_bytes ( ) . to_vec ( ) , value : st . value . unwrap ( ) . as_bytes ( ) . to_vec ( ) , } ) ) . await { Ok ( _ ) => ExecResult :: Success , Err ( e ) => { eprintln ! ( " " e message ( ) ) ; ExecResult :: Failed } } , StatementType :: Get => match self . store . get ( Request :: new ( Byte { body : key . as_bytes ( ) . to_vec ( ) , } ) ) . await { Ok ( res ) => { println ! ( " " String from_utf8 ( res into_inner ( ) body ) unwrap ( ) ) ; ExecResult :: Success } Err ( e ) => { // If the key doesn't exist, get() explicitly returns this, // so print the desired Error message. eprintln ! ( " " e message ( ) ) ; ExecResult :: Failed } } , StatementType :: Del => match self . store . del ( Request :: new ( Byte { body : key . as_bytes ( ) . to_vec ( ) , } ) ) . await { Ok ( _ ) => ExecResult :: Success , Err ( e ) => { eprintln ! ( " " e message ( ) ) ; ExecResult :: Failed } } , StatementType :: Unk => { eprintln ! ( " " self cmd ) ; ExecResult :: Failed } StatementType :: Fail => ExecResult :: Failed , } { ExecResult :: Failed => eprintln ! ( " " ) , ExecResult :: Success => println ! ( " " ) , } } }
Parses Commands from the REPL.
Parses Commands from the REPL .
&mut self