add time querying to io trait

This commit is contained in:
mazchew
2024-08-25 16:33:12 +08:00
parent 84ed081f19
commit 671b61ba19
7 changed files with 38 additions and 0 deletions

View File

@@ -110,6 +110,10 @@ impl IO for DarwinIO {
getrandom::getrandom(&mut buf).unwrap();
i64::from_ne_bytes(buf)
}
fn get_current_time(&self) -> String {
chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string()
}
}
enum CompletionCallback {

View File

@@ -30,6 +30,10 @@ impl IO for GenericIO {
getrandom::getrandom(&mut buf).unwrap();
i64::from_ne_bytes(buf)
}
fn get_current_time(&self) -> String {
chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string()
}
}
pub struct GenericFile {

View File

@@ -111,6 +111,10 @@ impl IO for LinuxIO {
getrandom::getrandom(&mut buf).unwrap();
i64::from_ne_bytes(buf)
}
fn get_current_time(&self) -> String {
chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string()
}
}
pub struct LinuxFile {

View File

@@ -22,6 +22,8 @@ pub trait IO {
fn run_once(&self) -> Result<()>;
fn generate_random_number(&self) -> i64;
fn get_current_time(&self) -> String;
}
pub type Complete = dyn Fn(Rc<RefCell<Buffer>>);

View File

@@ -30,6 +30,10 @@ impl IO for WindowsIO {
getrandom::getrandom(&mut buf).unwrap();
i64::from_ne_bytes(buf)
}
fn get_current_time(&self) -> String {
chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string()
}
}
pub struct WindowsFile {