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

Leave dynamic dispatch in FaktoryCommand's issue fixing clippy's warnings #38

Closed
wants to merge 1 commit into from
Closed
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
27 changes: 13 additions & 14 deletions src/proto/single/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
use std::io::prelude::*;

pub trait FaktoryCommand {
fn issue<W: Write>(&self, w: &mut dyn Write) -> Result<(), Error>;
fn issue(&self, w: &mut dyn Write) -> Result<(), Error>;
}

/// Write queues as part of a command. They are written with a leading space
/// followed by space separated queue names.
fn write_queues<W, S>(w: &mut dyn Write, queues: &[S]) -> Result<(), Error>
fn write_queues<S>(w: &mut dyn Write, queues: &[S]) -> Result<(), Error>
where
W: Write,
S: AsRef<str>,
{
for q in queues {
Expand All @@ -26,7 +25,7 @@
pub struct Info;

impl FaktoryCommand for Info {
fn issue<W: Write>(&self, w: &mut dyn Write) -> Result<(), Error> {
fn issue(&self, w: &mut dyn Write) -> Result<(), Error> {

Check warning on line 28 in src/proto/single/cmd.rs

View check run for this annotation

Codecov / codecov/patch

src/proto/single/cmd.rs#L28

Added line #L28 was not covered by tests
Ok(w.write_all(b"INFO\r\n")?)
}
}
Expand All @@ -40,7 +39,7 @@
}

impl FaktoryCommand for Ack {
fn issue<W: Write>(&self, w: &mut dyn Write) -> Result<(), Error> {
fn issue(&self, w: &mut dyn Write) -> Result<(), Error> {
w.write_all(b"ACK ")?;
serde_json::to_writer(&mut *w, self).map_err(Error::Serialization)?;
Ok(w.write_all(b"\r\n")?)
Expand All @@ -63,7 +62,7 @@
}

impl FaktoryCommand for Heartbeat {
fn issue<W: Write>(&self, w: &mut dyn Write) -> Result<(), Error> {
fn issue(&self, w: &mut dyn Write) -> Result<(), Error> {
w.write_all(b"BEAT ")?;
serde_json::to_writer(&mut *w, self).map_err(Error::Serialization)?;
Ok(w.write_all(b"\r\n")?)
Expand All @@ -90,7 +89,7 @@
}

impl FaktoryCommand for Fail {
fn issue<W: Write>(&self, w: &mut dyn Write) -> Result<(), Error> {
fn issue(&self, w: &mut dyn Write) -> Result<(), Error> {
w.write_all(b"FAIL ")?;
serde_json::to_writer(&mut *w, self).map_err(Error::Serialization)?;
Ok(w.write_all(b"\r\n")?)
Expand Down Expand Up @@ -121,7 +120,7 @@
pub struct End;

impl FaktoryCommand for End {
fn issue<W: Write>(&self, w: &mut dyn Write) -> Result<(), Error> {
fn issue(&self, w: &mut dyn Write) -> Result<(), Error> {
Ok(w.write_all(b"END\r\n")?)
}
}
Expand All @@ -139,12 +138,12 @@
where
S: AsRef<str>,
{
fn issue<W: Write>(&self, w: &mut dyn Write) -> Result<(), Error> {
fn issue(&self, w: &mut dyn Write) -> Result<(), Error> {
if self.queues.is_empty() {
w.write_all(b"FETCH\r\n")?;
} else {
w.write_all(b"FETCH")?;
write_queues::<W, _>(w, self.queues)?;
write_queues::<_>(w, self.queues)?;
w.write_all(b"\r\n")?;
}
Ok(())
Expand Down Expand Up @@ -210,7 +209,7 @@
}

impl FaktoryCommand for Hello {
fn issue<W: Write>(&self, w: &mut dyn Write) -> Result<(), Error> {
fn issue(&self, w: &mut dyn Write) -> Result<(), Error> {
w.write_all(b"HELLO ")?;
serde_json::to_writer(&mut *w, self).map_err(Error::Serialization)?;
Ok(w.write_all(b"\r\n")?)
Expand All @@ -236,7 +235,7 @@
}

impl FaktoryCommand for Push {
fn issue<W: Write>(&self, w: &mut dyn Write) -> Result<(), Error> {
fn issue(&self, w: &mut dyn Write) -> Result<(), Error> {
w.write_all(b"PUSH ")?;
serde_json::to_writer(&mut *w, &**self).map_err(Error::Serialization)?;
Ok(w.write_all(b"\r\n")?)
Expand All @@ -259,14 +258,14 @@
}

impl<S: AsRef<str>> FaktoryCommand for QueueControl<'_, S> {
fn issue<W: Write>(&self, w: &mut dyn Write) -> Result<(), Error> {
fn issue(&self, w: &mut dyn Write) -> Result<(), Error> {
let command = match self.action {
QueueAction::Pause => b"QUEUE PAUSE".as_ref(),
QueueAction::Resume => b"QUEUE RESUME".as_ref(),
};

w.write_all(command)?;
write_queues::<W, _>(w, self.queues)?;
write_queues::<_>(w, self.queues)?;
Ok(w.write_all(b"\r\n")?)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/proto/single/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl Job {
}

pub fn write_command<W: Write, C: FaktoryCommand>(w: &mut W, command: &C) -> Result<(), Error> {
command.issue::<W>(w)?;
command.issue(w)?;
Ok(w.flush()?)
}

Expand Down
Loading