refactor & fixed assembler path handling

This commit is contained in:
2025-06-21 04:05:22 +01:00
parent 42c26d4184
commit 528ceddade
17 changed files with 447 additions and 184 deletions
+94
View File
@@ -0,0 +1,94 @@
use std::{fmt, sync::mpsc::Sender};
#[allow(dead_code)]
#[derive(Debug)]
pub struct Logger {
pub sender: Sender<Entry>,
}
impl Logger {
pub fn new(sender: Sender<Entry>) -> Self {
Self { sender }
}
pub fn debug<T: fmt::Display>(&self, message: T) {
self.sender
.send(Entry {
etype: EntryType::Debug,
message: message.to_string(),
})
.unwrap();
}
pub fn info<T: fmt::Display>(&self, message: T) {
self.sender
.send(Entry {
etype: EntryType::Info,
message: message.to_string(),
})
.unwrap();
}
pub fn warn<T: fmt::Display>(&self, message: T) {
self.sender
.send(Entry {
etype: EntryType::Warn,
message: message.to_string(),
})
.unwrap();
}
pub fn error<T: fmt::Display>(&self, message: T) {
self.sender
.send(Entry {
etype: EntryType::Error,
message: message.to_string(),
})
.unwrap();
}
pub fn fatal<T: fmt::Display>(&self, message: T) {
self.sender
.send(Entry {
etype: EntryType::Fatal,
message: message.to_string(),
})
.unwrap();
}
}
pub struct Entry {
etype: EntryType,
pub message: String,
}
#[derive(Copy, Clone, Eq, PartialEq)]
enum EntryType {
Debug,
Info,
Warn,
Error,
Fatal,
}
impl fmt::Display for EntryType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{:<5}",
match self {
EntryType::Debug => "DEBUG",
EntryType::Info => "INFO",
EntryType::Warn => "WARN",
EntryType::Error => "ERROR",
EntryType::Fatal => "FATAL",
}
)
}
}
impl fmt::Display for Entry {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}: {}", self.etype, self.message)
}
}