use super::level::Level;
#[derive(Debug, Clone)]
pub struct Record<'a> {
level: Level,
message: &'a str,
module_path: &'static str,
file: &'static str,
line: u32,
}
impl<'a> Record<'a> {
#[must_use]
pub const fn builder(level: Level) -> RecordBuilder<'a> {
RecordBuilder::new(level)
}
#[must_use]
pub const fn level(&self) -> Level {
self.level
}
#[must_use]
pub const fn message(&self) -> &str {
self.message
}
#[must_use]
pub const fn module_path(&self) -> &'static str {
self.module_path
}
#[must_use]
pub const fn file(&self) -> &'static str {
self.file
}
#[must_use]
pub const fn line(&self) -> u32 {
self.line
}
}
#[derive(Debug)]
pub struct RecordBuilder<'a> {
level: Level,
message: &'a str,
module_path: &'static str,
file: &'static str,
line: u32,
}
impl<'a> RecordBuilder<'a> {
#[must_use]
const fn new(level: Level) -> Self {
Self {
level,
message: "",
module_path: "",
file: "",
line: 0,
}
}
#[must_use]
pub const fn message(mut self, message: &'a str) -> Self {
self.message = message;
self
}
#[must_use]
pub const fn module_path(mut self, module_path: &'static str) -> Self {
self.module_path = module_path;
self
}
#[must_use]
pub const fn file(mut self, file: &'static str) -> Self {
self.file = file;
self
}
#[must_use]
pub const fn line(mut self, line: u32) -> Self {
self.line = line;
self
}
#[must_use]
pub const fn build(self) -> Record<'a> {
Record {
level: self.level,
message: self.message,
module_path: self.module_path,
file: self.file,
line: self.line,
}
}
}