Crates.io | print_queues |
lib.rs | print_queues |
version | 1.0.9 |
source | src |
created_at | 2022-09-01 13:31:13.004551 |
updated_at | 2023-11-29 16:52:59.12784 |
description | A print queues that can be add from different thread and print on main thread |
homepage | |
repository | https://github.com/momozahara/print_queues_rs |
max_upload_size | |
id | 656695 |
size | 4,417 |
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
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();
/*
"John Doe"
"Hello: John doe"
*/
}
print_queues::add("John");
print_queues::add("Doe");
let r = print_queues::next().unwrap();
// John
let r = print_queues::next().unwrap();
// Doe
fn main() {
print_queues::init();
let th = std::thread::spawn(move || {
// some server or application loop that want to print
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)
);
}
}