pub struct LogInfo {
content:Vec<u8>,
}
impl LogInfo {
pub fn new( ) -> LogInfo {
LogInfo {
content:Vec::new(),
}
}
pub fn new_msg(msg: &str) -> Self {
let mut log = Self::new();
log.content.extend(msg.as_bytes());
log
}
pub fn extend(&mut self, msg: &str) -> &mut Self {
self.content.extend(msg.as_bytes());
self
}
pub fn merge_to_string(&self, separator: &str) -> String {
self.content
.iter()
.map(|&b| b as char)
.collect::<String>()
}
pub fn to_string_lossy(&self) -> String {
String::from_utf8_lossy(&self.content).to_string()
}
pub fn merge_multiple(logs: &[&LogInfo], separator: &str) -> String {
logs.iter()
.map(|log| String::from_utf8_lossy(&log.content).to_string())
.collect::<Vec<String>>()
.join(separator)
}
}