Skip to content

Commit

Permalink
feat: remove warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrs committed Mar 19, 2023
1 parent f6c3b49 commit 19a5044
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
11 changes: 5 additions & 6 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,24 @@ pub fn pack_record<'a>(
chunk: &'a str,
) -> Result<(), Error> {
buf.push(0x93);
encode::write_str(buf, tag).map_err(|e| Error::DeriveError(e.to_string()))?;
encode::write_array_len(buf, entries.len() as u32)
.map_err(|e| Error::DeriveError(e.to_string()))?;
encode::write_str(buf, tag).map_err(|e| Error::Derive(e.to_string()))?;
encode::write_array_len(buf, entries.len() as u32).map_err(|e| Error::Derive(e.to_string()))?;
for (t, entry) in entries {
buf.push(0x92);
t.write_time(buf)
.map_err(|e| Error::DeriveError(e.to_string()))?;
.map_err(|e| Error::Derive(e.to_string()))?;
buf.extend(entry.iter());
}
let options = Options {
chunk: chunk.to_string(),
};

rencode::write_named(buf, &options).map_err(|e| Error::DeriveError(e.to_string()))
rencode::write_named(buf, &options).map_err(|e| Error::Derive(e.to_string()))
}

pub fn unpack_response(resp_buf: &[u8], size: usize) -> Result<AckReply, Error> {
let mut de = Deserializer::new(&resp_buf[0..size]);
Deserialize::deserialize(&mut de).map_err(|e| Error::DeriveError(e.to_string()))
Deserialize::deserialize(&mut de).map_err(|e| Error::Derive(e.to_string()))
}

#[cfg(test)]
Expand Down
6 changes: 3 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ impl Client for WorkerPool {
}

let mut buf = Vec::new();
rencode::write_named(&mut buf, a).map_err(|e| Error::DeriveError(e.to_string()))?;
rencode::write_named(&mut buf, a).map_err(|e| Error::Derive(e.to_string()))?;

self.sender
.send(Message::Queuing(tag, timestamp, buf))
.map_err(|e| Error::SendError(e.to_string()))?;
.map_err(|e| Error::Send(e.to_string()))?;
Ok(())
}

Expand All @@ -98,7 +98,7 @@ impl Client for WorkerPool {
self.sender.send(Message::Terminating(sender)).unwrap();
receiver
.recv()
.map_err(|e| Error::TerminateError(e.to_string()))?;
.map_err(|e| Error::Terminate(e.to_string()))?;

Ok(())
}
Expand Down
12 changes: 6 additions & 6 deletions src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ where
let op = || {
if self.should_reconnect() {
self.reconnect()
.map_err(|e| RetryError::transient(Error::NetworkError(e.to_string())))?;
.map_err(|e| RetryError::transient(Error::Network(e.to_string())))?;
}
self.write_all(buf)
.and_then(|_| self.flush())
Expand All @@ -158,7 +158,7 @@ where
if let Err(err) = self.close() {
debug!("Failed to close the stream, cause: {:?}", err);
}
RetryError::transient(Error::NetworkError(e.to_string()))
RetryError::transient(Error::Network(e.to_string()))
})?;

let read_backoff = ExponentialBackoff {
Expand All @@ -177,16 +177,16 @@ where
use io::ErrorKind::*;
match e.kind() {
WouldBlock | TimedOut => {
RetryError::transient(Error::NetworkError(e.to_string()))
RetryError::transient(Error::Network(e.to_string()))
}
UnexpectedEof | BrokenPipe | ConnectionAborted | ConnectionRefused
| ConnectionReset => {
if let Err(err) = self.close() {
debug!("Failed to close the stream, cause: {:?}", err);
}
RetryError::permanent(Error::NetworkError(e.to_string()))
RetryError::permanent(Error::Network(e.to_string()))
}
_ => RetryError::Permanent(Error::NetworkError(e.to_string())),
_ => RetryError::Permanent(Error::Network(e.to_string())),
}
})
};
Expand Down Expand Up @@ -215,7 +215,7 @@ where
reply.ack, chunk
);

Err(RetryError::transient(Error::AckUmatchedError(
Err(RetryError::transient(Error::AckUmatched(
reply.ack,
chunk.to_string(),
)))
Expand Down
5 changes: 3 additions & 2 deletions src/emitter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::buffer::{self, Take};
use crate::connect::*;
use crate::error::Error;
use base64::{engine::general_purpose, Engine as _};
use std::cell::RefCell;
use std::cmp;
use std::collections::VecDeque;
Expand Down Expand Up @@ -37,7 +38,7 @@ impl Emitter {
let mut entries = Vec::with_capacity(cmp::min(qlen, size.unwrap_or(qlen)));
queue.take(&mut entries);

let chunk = base64::encode(&Uuid::new_v4().to_string());
let chunk = general_purpose::STANDARD.encode(Uuid::new_v4());

let mut buf = Vec::new();
buffer::pack_record(
Expand Down Expand Up @@ -117,7 +118,7 @@ mod test {

impl WriteRead for TestErrStream {
fn write_and_read(&mut self, _buf: &[u8], _chunk: &str) -> Result<(), Error> {
Err(Error::AckUmatchedError("a".to_string(), "b".to_string()))
Err(Error::AckUmatched("a".to_string(), "b".to_string()))
}
}

Expand Down
32 changes: 16 additions & 16 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@ use std::fmt;

#[derive(Debug)]
pub enum Error {
NetworkError(String),
DeriveError(String),
SendError(String),
TerminateError(String),
AckUmatchedError(String, String),
EmittingTimeoutError,
ConnectingTimeoutError,
NoAckResponseError,
Network(String),
Derive(String),
Send(String),
Terminate(String),
AckUmatched(String, String),
EmittingTimeout,
ConnectingTimeout,
NoAckResponse,
}

impl StdError for Error {}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match *self {
Error::NetworkError(ref e) => e,
Error::DeriveError(ref e) => e,
Error::SendError(ref e) => e,
Error::TerminateError(ref e) => e,
Error::AckUmatchedError(_, _) => "request chunk and response ack-id did not match",
Error::EmittingTimeoutError => "emitting timeout",
Error::ConnectingTimeoutError => "connecting timeout",
Error::NoAckResponseError => "no ack response",
Error::Network(ref e) => e,
Error::Derive(ref e) => e,
Error::Send(ref e) => e,
Error::Terminate(ref e) => e,
Error::AckUmatched(_, _) => "request chunk and response ack-id did not match",
Error::EmittingTimeout => "emitting timeout",
Error::ConnectingTimeout => "connecting timeout",
Error::NoAckResponse => "no ack response",
};
write!(f, "{}", s)
}
Expand Down

0 comments on commit 19a5044

Please sign in to comment.