Skip to content

Commit

Permalink
Parse set arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
gillchristian committed Aug 9, 2024
1 parent 4f4d2fe commit 985c8f9
Show file tree
Hide file tree
Showing 3 changed files with 414 additions and 13 deletions.
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

0 comments on commit 985c8f9

Please sign in to comment.