sonic_channel/commands/
pop.rs1use super::StreamCommand;
2use crate::misc::ObjDest;
3use crate::protocol;
4use crate::result::*;
5
6#[derive(Debug)]
8pub struct PopRequest {
9 pub dest: ObjDest,
11 pub text: String,
13}
14
15impl PopRequest {
16 pub fn new(dest: ObjDest, text: impl ToString) -> Self {
18 Self {
19 dest,
20 text: text.to_string(),
21 }
22 }
23}
24
25#[derive(Debug)]
26pub struct PopCommand {
27 pub(crate) req: PopRequest,
28}
29
30impl StreamCommand for PopCommand {
31 type Response = usize;
32
33 fn request(&self) -> protocol::Request {
34 let dest = &self.req.dest;
35 protocol::Request::Pop {
36 collection: dest.collection().clone(),
37 bucket: dest
38 .bucket_opt()
39 .cloned()
40 .unwrap_or_else(|| String::from("default")),
42 object: dest.object().clone(),
43 terms: self.req.text.to_string(),
44 }
45 }
46
47 fn receive(&self, res: protocol::Response) -> Result<Self::Response> {
48 if let protocol::Response::Result(count) = res {
49 Ok(count)
50 } else {
51 Err(Error::WrongResponse)
52 }
53 }
54}