Skip to content

Commit

Permalink
Use W:Write generic in FaktoryCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
rustworthy committed Dec 25, 2023
1 parent 481b152 commit 829d069
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/proto/single/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ 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<W: Write>(&self, w: &mut W) -> 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<W, S>(w: &mut W, queues: &[S]) -> Result<(), Error>
where
W: Write,
S: AsRef<str>,
Expand All @@ -26,7 +26,7 @@ where
pub struct Info;

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

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

View check run for this annotation

Codecov / codecov/patch

src/proto/single/cmd.rs#L29

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

impl FaktoryCommand for Ack {
fn issue<W: Write>(&self, w: &mut dyn Write) -> Result<(), Error> {
fn issue<W: Write>(&self, w: &mut W) -> 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 +63,7 @@ pub struct Heartbeat {
}

impl FaktoryCommand for Heartbeat {
fn issue<W: Write>(&self, w: &mut dyn Write) -> Result<(), Error> {
fn issue<W: Write>(&self, w: &mut W) -> 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 +90,7 @@ pub struct Fail {
}

impl FaktoryCommand for Fail {
fn issue<W: Write>(&self, w: &mut dyn Write) -> Result<(), Error> {
fn issue<W: Write>(&self, w: &mut W) -> 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 +121,7 @@ impl Fail {
pub struct End;

impl FaktoryCommand for End {
fn issue<W: Write>(&self, w: &mut dyn Write) -> Result<(), Error> {
fn issue<W: Write>(&self, w: &mut W) -> Result<(), Error> {
Ok(w.write_all(b"END\r\n")?)
}
}
Expand All @@ -139,7 +139,7 @@ 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<W: Write>(&self, w: &mut W) -> Result<(), Error> {
if self.queues.is_empty() {
w.write_all(b"FETCH\r\n")?;
} else {
Expand Down Expand Up @@ -210,7 +210,7 @@ impl Hello {
}

impl FaktoryCommand for Hello {
fn issue<W: Write>(&self, w: &mut dyn Write) -> Result<(), Error> {
fn issue<W: Write>(&self, w: &mut W) -> 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 +236,7 @@ impl From<Job> for Push {
}

impl FaktoryCommand for Push {
fn issue<W: Write>(&self, w: &mut dyn Write) -> Result<(), Error> {
fn issue<W: Write>(&self, w: &mut W) -> 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,7 +259,7 @@ where
}

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

0 comments on commit 829d069

Please sign in to comment.