From ba0e9c3c9a674089918ffbec06a4540b53e712e7 Mon Sep 17 00:00:00 2001 From: zxj Date: Wed, 18 May 2022 14:25:52 +0800 Subject: [PATCH] impl Eq --- src/appender.rs | 27 +++++++++++++++++++++------ src/fast_log.rs | 8 ++------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/appender.rs b/src/appender.rs index 948754f..bfc1624 100644 --- a/src/appender.rs +++ b/src/appender.rs @@ -1,4 +1,3 @@ - use log::{LevelFilter}; use std::time::{Duration, SystemTime}; use std::ops::{Add, Sub}; @@ -32,6 +31,23 @@ pub enum Command { CommandFlush(WaitGroup), } +impl Command { + pub fn to_i32(&self) -> i32 { + match self { + Command::CommandRecord => { 1 } + Command::CommandExit => { 2 } + Command::CommandFlush(_) => { 3 } + } + } +} + +impl PartialEq for Command { + fn eq(&self, other: &Self) -> bool { + self.to_i32().eq(&other.to_i32()) + } +} +impl Eq for Command{} + #[derive(Clone, Debug)] pub struct FastLogRecord { pub command: Command, @@ -55,10 +71,10 @@ pub struct FastLogFormatRecord { pub display_file: log::LevelFilter, } -fn to_zero_left(arg:u8)->String{ - if arg<=9{ - return format!("0{}",arg); - }else{ +fn to_zero_left(arg: u8) -> String { + if arg <= 9 { + return format!("0{}", arg); + } else { return arg.to_string(); } } @@ -95,7 +111,6 @@ impl RecordFormat for FastLogFormatRecord { } impl FastLogFormatRecord { - pub fn local_duration() -> Duration { let utc = chrono::Utc::now().naive_utc(); let tz = chrono::Local::now().naive_local(); diff --git a/src/fast_log.rs b/src/fast_log.rs index 717491e..a8926af 100644 --- a/src/fast_log.rs +++ b/src/fast_log.rs @@ -168,12 +168,8 @@ pub fn init(config: Config) -> Result<&'static Logger, LogError> { let mut exit = false; for x in &mut remain { x.formated = format.do_format(x); - match x.command { - Command::CommandRecord => {} - Command::CommandExit => { - exit = true; - } - Command::CommandFlush(_) => {} + if x.command.eq(&Command::CommandExit){ + exit = true; } } let data = Arc::new(remain);