Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse set arguments #49

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ pub enum Command {

impl Executable for Command {
fn exec(self, store: Store) -> Result<Frame, Error> {
// TODO: can we use a macro for this patter matching ???
match self {
Command::Append(cmd) => cmd.exec(store),
Command::Client(cmd) => cmd.exec(store),
Expand Down Expand Up @@ -171,6 +172,7 @@ impl TryFrom<Frame> for Command {
}
};

// TODO: should we pass the frame directly ?
let parser = &mut CommandParser {
parts: frames.into_iter(),
};
Expand Down Expand Up @@ -219,7 +221,9 @@ impl TryFrom<Frame> for Command {
}
}

// TODO: can we use Impl<Iterator> ??? Or Iterator
struct CommandParser {
// parts: dyn Iterator<Item = Frame>,
parts: vec::IntoIter<Frame>,
}

Expand Down Expand Up @@ -339,6 +343,11 @@ impl CommandParser {
}),
}
}

// TODO: !!!
fn has_more(&mut self) -> bool {
self.parts.clone().peekable().peek().is_some()
}
}

#[derive(Debug, ThisError, PartialEq)]
Expand Down Expand Up @@ -407,7 +416,10 @@ mod tests {
set_command,
Command::Set(Set {
key: String::from("foo"),
value: Bytes::from("baz")
value: Bytes::from("baz"),
ttl: None,
behavior: None,
get: false
})
);

Expand All @@ -423,7 +435,10 @@ mod tests {
set_command,
Command::Set(Set {
key: String::from("foo"),
value: Bytes::from("baz")
value: Bytes::from("baz"),
ttl: None,
behavior: None,
get: false
})
);

Expand All @@ -439,7 +454,10 @@ mod tests {
set_command,
Command::Set(Set {
key: String::from("foo"),
value: Bytes::from("baz")
value: Bytes::from("baz"),
ttl: None,
behavior: None,
get: false
})
);

Expand All @@ -455,7 +473,10 @@ mod tests {
set_command,
Command::Set(Set {
key: String::from("foo"),
value: Bytes::from("baz")
value: Bytes::from("baz"),
ttl: None,
behavior: None,
get: false
})
);
}
Expand Down
Loading
Loading