a1ien / rusb

A safe Rust wrapper for libusb.
Other
382 stars 78 forks source link

Log callback API added #194

Closed dmitry-zakablukov closed 4 months ago

dmitry-zakablukov commented 4 months ago

Good day.

This pr suggests some API updates to support log callbacks.

Log callback setup:

let mut context = rusb::Context::new()?;
context.set_log_level(rusb::LogLevel::Info);

let cb = Box::new(move |level: rusb::LogLevel, text: String| {
    println!(log_file, "[{:#?}] {}", level, text).ok();
});

context.set_log_callback(cb, rusb::LogCallbackMode::Context);

You can take this changes as a base for your own API or just merge it as is.

a1ien commented 4 months ago

Thank you. LGTM.