Skip to content

Commit

Permalink
impl Eq
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed May 18, 2022
1 parent a815765 commit ba0e9c3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
27 changes: 21 additions & 6 deletions src/appender.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use log::{LevelFilter};
use std::time::{Duration, SystemTime};
use std::ops::{Add, Sub};
Expand Down Expand Up @@ -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,
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 2 additions & 6 deletions src/fast_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ba0e9c3

Please sign in to comment.