diff --git a/justfile b/justfile new file mode 100644 index 0000000..21ac29d --- /dev/null +++ b/justfile @@ -0,0 +1,2 @@ +bench NAME='': + RUSTFLAGS="-C target-cpu=native" cargo bench {{NAME}} diff --git a/src/influx.rs b/src/influx.rs index 795d7f5..ce08407 100644 --- a/src/influx.rs +++ b/src/influx.rs @@ -225,9 +225,6 @@ pub fn serialize_owned(measurement: &OwnedMeasurement, line: &mut String) { } } - - - pub fn writer(warnings: Sender) -> thread::JoinHandle<()> { thread::spawn(move || { let _ = fs::create_dir("/tmp/mm"); @@ -262,14 +259,14 @@ pub fn writer(warnings: Sender) -> thread::JoinHandle<()> { Ok(mut resp) => { resp.read_to_string(&mut server_resp); //.unwrap_or(0); - warnings.send( + let _ = warnings.send( Warning::Error( format!("Influx server: {}", server_resp))); server_resp.clear(); } Err(why) => { - warnings.send( + let _ = warnings.send( Warning::Error( format!("Influx write error: {}", why))); } @@ -292,7 +289,7 @@ pub enum OwnedValue { Boolean(bool) } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct OwnedMeasurement { pub key: &'static str, pub timestamp: Option, @@ -482,7 +479,7 @@ impl InfluxWriter { impl Drop for InfluxWriter { fn drop(&mut self) { - self.kill_switch.send(()); + let _ = self.kill_switch.send(()).unwrap(); if let Some(thread) = self.thread.take() { let _ = thread.join(); } diff --git a/src/warnings.rs b/src/warnings.rs index 6da0a3d..a937b4a 100644 --- a/src/warnings.rs +++ b/src/warnings.rs @@ -26,7 +26,7 @@ const N_WARNINGS: usize = 500; macro_rules! confirmed { ($warnings:ident, $($args:tt)*) => ( { - $warnings.send(Warning::Confirmed( ( format!($($args)*) ) ) ).unwrap(); + $let _ = warnings.send(Warning::Confirmed( ( format!($($args)*) ) ) ).unwrap(); } ) } @@ -136,51 +136,52 @@ impl Warning { } } - pub fn category(&self, f: &mut Formatter) { - match self { - &Warning::Notice(_) => { - write!(f, "[ Notice ]"); + pub fn category(&self, f: &mut Formatter) -> fmt::Result { + match *self { + Warning::Notice(_) => { + write!(f, "[ Notice ]") } - &Warning::Error(_) => { + Warning::Error(_) => { write!(f, "{yellow}[{title}]{reset}", yellow = Fg(color::LightYellow), title = " Error--", - reset = Fg(color::Reset)); + reset = Fg(color::Reset)) } - &Warning::Critical(_) => { + + Warning::Critical(_) => { write!(f, "{bg}{fg}{title}{resetbg}{resetfg}", bg = Bg(color::Red), fg = Fg(color::White), title = " CRITICAL ", resetbg = Bg(color::Reset), - resetfg = Fg(color::Reset)); + resetfg = Fg(color::Reset)) } - &Warning::Awesome(_) => { + Warning::Awesome(_) => { write!(f, "{color}[{title}]{reset}", color = Fg(color::Green), title = "Awesome!", - reset = Fg(color::Reset)); + reset = Fg(color::Reset)) } - &Warning::DegradedService(_) => { + Warning::DegradedService(_) => { write!(f, "{color}[{title}] {reset}", color = Fg(color::Blue), title = "Degraded Service ", - reset = Fg(color::Reset)); + reset = Fg(color::Reset)) } - &Warning::Confirmed(_) => { + + Warning::Confirmed(_) => { write!(f, "{bg}{fg}{title}{resetbg}{resetfg}", bg = Bg(color::Blue), fg = Fg(color::White), title = "Confirmed ", resetbg = Bg(color::Reset), - resetfg = Fg(color::Reset)); + resetfg = Fg(color::Reset)) } - - _ => {} + _ => Ok(()) } } } @@ -394,7 +395,7 @@ impl Drain for WarningsDrain { record.kv().serialize(record, &mut ser); let msg = record.msg().to_string(); if let Ok(lock) = self.tx.lock() { - lock.send(Warning::Log { + let _ = lock.send(Warning::Log { level: record.level(), module: record.module(), function: record.function(), @@ -450,7 +451,7 @@ impl WarningsManager { meas.add_field("msg", InfluentValue::String(msg.as_ref())); meas.add_tag("category", level.as_short_str()); influx::serialize(&meas, &mut buf); - socket.send_str(&buf, 0); + let _ = socket.send_str(&buf, 0); buf.clear(); // and don't push to warnings // bc it's debug @@ -463,7 +464,7 @@ impl WarningsManager { { let m = rec.to_measurement(measurement_name); influx::serialize(&m, &mut buf); - socket.send_str(&buf, 0); + let _ = socket.send_str(&buf, 0); buf.clear(); } if let Ok(mut lock) = warnings.write() { @@ -486,7 +487,7 @@ impl WarningsManager { impl Drop for WarningsManager { fn drop(&mut self) { - self.tx.send(Warning::Terminate); + let _ = self.tx.send(Warning::Terminate); if let Some(thread) = self.thread.take() { thread.join(); } @@ -552,7 +553,7 @@ impl Drain for ZmqDrain values.serialize(record, &mut kv_ser); } - self.socket.send(&buf, 0); + let _ = self.socket.send(&buf, 0); buf.clear(); } self.drain.log(record, values) @@ -588,12 +589,12 @@ impl Write for ZmqIo { fn flush(&mut self) -> io::Result<()> { match self.buf.pop() { Some(b'\n') => { - self.socket.send(&self.buf, 0); + let _ = self.socket.send(&self.buf, 0); } Some(other) => { self.buf.push(other); - self.socket.send(&self.buf, 0); + let _ = self.socket.send(&self.buf, 0); } None => { @@ -759,9 +760,9 @@ mod tests { let tx = Arc::new(Mutex::new(tx)); b.iter(|| { let lock = tx.lock().unwrap(); - lock.send(Msg::Val(1)); + let _ = lock.send(Msg::Val(1)); }); - tx.lock().unwrap().send(Msg::Terminate); + let _ = tx.lock().unwrap().send(Msg::Terminate); let len = worker.join().unwrap(); //println!("{}", len);