Print Queues
A print queue that can be add from different thread and print on main thread
just use tracing fr fr this is project to learn how to publish on crates.io
Usage
Simple Usage
struct Person<'a> {
name: &'a str,
}
impl<'a> std::fmt::Display for Person<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Hello: {}", self.name)
}
}
fn main() {
let person = Person { name: "John doe" };
print_queues::init();
print_queues::add("John Doe");
print_queues::add(person);
print_queues::print();
}
print_queues::add("John");
print_queues::add("Doe");
let r = print_queues::next().unwrap();
let r = print_queues::next().unwrap();
Thread Usage
fn main() {
print_queues::init();
let th = std::thread::spawn(move || {
print_queues::add("Hello, Server!");
std::thread::sleep(
std::time::Duration::from_secs(3)
);
});
while !th.is_finished() {
print_queues::print();
std::thread::sleep(
std::time::Duration::from_millis(1)
);
}
}