refactor(command): generic execute and result type

This commit is contained in:
Khaïs COLIN 2025-05-02 20:53:12 +02:00
parent 711d51090e
commit 5b6d878208
3 changed files with 39 additions and 12 deletions

View file

@ -1,11 +1,38 @@
use crate::meta_commands::{MetaCommand, MetaCommandParseError};
use crate::statements::{Statement, StatementParseError};
use crate::meta_commands::{MetaCommand, MetaCommandExecuteResult, MetaCommandParseError};
use crate::statements::{Statement, StatementExecuteResult, StatementParseError};
pub enum Command {
MetaCommand(MetaCommand),
Statement(Statement),
}
pub struct CommandExecuteResult {
pub should_exit: bool,
}
impl From<MetaCommandExecuteResult> for CommandExecuteResult {
fn from(value: MetaCommandExecuteResult) -> Self {
Self {
should_exit: value.should_exit,
}
}
}
impl From<StatementExecuteResult> for CommandExecuteResult {
fn from(_value: StatementExecuteResult) -> Self {
Self { should_exit: false }
}
}
impl Command {
pub fn execute(&self) -> CommandExecuteResult {
match self {
Command::MetaCommand(cmd) => cmd.execute().into(),
Command::Statement(stmt) => stmt.execute().into(),
}
}
}
pub enum CommandParseError {
MetaCommand(MetaCommandParseError),
Statement(StatementParseError),