sonic_channel/commands/
trigger.rs1use super::StreamCommand;
2use crate::protocol;
3use crate::result::*;
4use std::path::PathBuf;
5
6#[derive(Debug)]
8pub enum TriggerRequest<'a> {
9 Consolidate,
12
13 Backup(&'a str),
17
18 Restore(&'a str),
20}
21
22#[derive(Debug)]
23pub struct TriggerCommand<'a> {
24 pub(crate) req: TriggerRequest<'a>,
25}
26
27impl StreamCommand for TriggerCommand<'_> {
28 type Response = ();
29
30 fn request(&self) -> protocol::Request {
31 let req = match self.req {
32 TriggerRequest::Consolidate => protocol::TriggerRequest::Consolidate,
33 TriggerRequest::Backup(path) => protocol::TriggerRequest::Backup(PathBuf::from(path)),
34 TriggerRequest::Restore(path) => protocol::TriggerRequest::Restore(PathBuf::from(path)),
35 };
36
37 protocol::Request::Trigger(req)
38 }
39
40 fn receive(&self, res: protocol::Response) -> Result<Self::Response> {
41 if matches!(res, protocol::Response::Ok) {
42 Ok(())
43 } else {
44 Err(Error::WrongResponse)
45 }
46 }
47}