Skip to content

Commit

Permalink
Rm unused type param 'W' for writer
Browse files Browse the repository at this point in the history
  • Loading branch information
rustworthy committed Dec 25, 2023
1 parent b63eadf commit 2bc3271
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
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 crate::{error::Error, Job};
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 @@ where
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 @@ pub struct Ack {
}

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 @@ pub struct Heartbeat {
}

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 @@ pub struct Fail {
}

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 @@ impl Fail {
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 @@ impl<'a, S> FaktoryCommand for Fetch<'a, S>
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 Hello {
}

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 From<Job> for Push {
}

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 @@ where
}

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

0 comments on commit 2bc3271

Please sign in to comment.