style: cosmetic changes
This commit is contained in:
parent
f750de076e
commit
f2f49be0ec
7 changed files with 60 additions and 55 deletions
|
@ -40,7 +40,7 @@ pub(crate) use query::QueryCommand;
|
||||||
pub(crate) use suggest::SuggestCommand;
|
pub(crate) use suggest::SuggestCommand;
|
||||||
|
|
||||||
#[cfg(feature = "control")]
|
#[cfg(feature = "control")]
|
||||||
pub(crate) use trigger::{TriggerCommand, TriggerAction};
|
pub(crate) use trigger::{TriggerAction, TriggerCommand};
|
||||||
|
|
||||||
use crate::result::Result;
|
use crate::result::Result;
|
||||||
|
|
||||||
|
|
|
@ -24,12 +24,11 @@ impl StreamCommand for PopCommand<'_> {
|
||||||
fn receive(&self, message: String) -> Result<Self::Response> {
|
fn receive(&self, message: String) -> Result<Self::Response> {
|
||||||
if message.starts_with("RESULT ") {
|
if message.starts_with("RESULT ") {
|
||||||
let count = message.split_whitespace().last().unwrap_or_default();
|
let count = message.split_whitespace().last().unwrap_or_default();
|
||||||
count
|
count.parse().map_err(|_| {
|
||||||
.parse()
|
Error::new(ErrorKind::QueryResponseError(
|
||||||
.map_err(|_| Error::new(ErrorKind::QueryResponseError(
|
|
||||||
"Cannot parse count of pop method response to usize",
|
"Cannot parse count of pop method response to usize",
|
||||||
)))
|
))
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
Err(Error::new(ErrorKind::WrongSonicResponse))
|
Err(Error::new(ErrorKind::WrongSonicResponse))
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,9 +43,7 @@ impl StreamCommand for QueryCommand<'_> {
|
||||||
|
|
||||||
dbg!(&message);
|
dbg!(&message);
|
||||||
|
|
||||||
match RE.captures(&message) {
|
if let Some(caps) = RE.captures(&message) {
|
||||||
None => Err(Error::new(ErrorKind::WrongSonicResponse)),
|
|
||||||
Some(caps) => {
|
|
||||||
if caps["pending_query_id"] != caps["event_query_id"] {
|
if caps["pending_query_id"] != caps["event_query_id"] {
|
||||||
Err(Error::new(ErrorKind::QueryResponseError(
|
Err(Error::new(ErrorKind::QueryResponseError(
|
||||||
"Pending id and event id don't match",
|
"Pending id and event id don't match",
|
||||||
|
@ -53,9 +51,13 @@ impl StreamCommand for QueryCommand<'_> {
|
||||||
} else if caps["objects"].is_empty() {
|
} else if caps["objects"].is_empty() {
|
||||||
Ok(vec![])
|
Ok(vec![])
|
||||||
} else {
|
} else {
|
||||||
Ok(caps["objects"].split_whitespace().map(str::to_owned).collect())
|
Ok(caps["objects"]
|
||||||
}
|
.split_whitespace()
|
||||||
|
.map(str::to_owned)
|
||||||
|
.collect())
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Err(Error::new(ErrorKind::WrongSonicResponse))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,7 @@ impl StreamCommand for StartCommand {
|
||||||
|
|
||||||
dbg!(&message);
|
dbg!(&message);
|
||||||
|
|
||||||
match RE.captures(&message) {
|
if let Some(caps) = RE.captures(&message) {
|
||||||
None => Err(Error::new(ErrorKind::SwitchMode)),
|
|
||||||
Some(caps) => {
|
|
||||||
if self.mode.to_str() != &caps["mode"] {
|
if self.mode.to_str() != &caps["mode"] {
|
||||||
Err(Error::new(ErrorKind::SwitchMode))
|
Err(Error::new(ErrorKind::SwitchMode))
|
||||||
} else {
|
} else {
|
||||||
|
@ -57,7 +55,8 @@ impl StreamCommand for StartCommand {
|
||||||
mode: self.mode,
|
mode: self.mode,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
Err(Error::new(ErrorKind::SwitchMode))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,10 @@ impl StreamCommand for SuggestCommand<'_> {
|
||||||
} else if caps["words"].is_empty() {
|
} else if caps["words"].is_empty() {
|
||||||
Ok(vec![])
|
Ok(vec![])
|
||||||
} else {
|
} else {
|
||||||
Ok(caps["words"].split_whitespace().map(str::to_owned).collect())
|
Ok(caps["words"]
|
||||||
|
.split_whitespace()
|
||||||
|
.map(str::to_owned)
|
||||||
|
.collect())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,9 @@
|
||||||
#![deny(clippy::all)]
|
#![deny(clippy::all)]
|
||||||
|
|
||||||
#[cfg(not(any(feature = "ingest", feature = "search", feature = "control")))]
|
#[cfg(not(any(feature = "ingest", feature = "search", feature = "control")))]
|
||||||
compile_error!(r#"Either features "ingest" or "search" or "control" must be enabled for "sonic-channel" crate"#);
|
compile_error!(
|
||||||
|
r#"Either features "ingest" or "search" or "control" must be enabled for "sonic-channel" crate"#
|
||||||
|
);
|
||||||
|
|
||||||
mod channel;
|
mod channel;
|
||||||
mod commands;
|
mod commands;
|
||||||
|
|
Loading…
Reference in a new issue