print_queues

Crates.ioprint_queues
lib.rsprint_queues
version1.0.9
sourcesrc
created_at2022-09-01 13:31:13.004551
updated_at2023-11-29 16:52:59.12784
descriptionA print queues that can be add from different thread and print on main thread
homepage
repositoryhttps://github.com/momozahara/print_queues_rs
max_upload_size
id656695
size4,417
Pream Pinbut (momozahara)

documentation

README

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();
    /*
        "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

Thread Usage

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)
        );
    }
}
Commit count: 18

cargo fmt