Skip to main content

set_status_handler

Function set_status_handler 

Source
pub fn set_status_handler(
    handler: impl FnMut(&str) -> ControlFlow<()> + 'static,
) -> StatusHandlerGuard
Expand description

Installs a Rust closure as the status handler of the calling thread until the returned guard is dropped.

Status messages are free-form notes about the stage a computation is in (as opposed to progress percentages). They are emitted with status; returning ControlFlow::Break makes the reporting call fail with ErrorKind::Interrupted.

Binds igraph_set_status_handler.

ยงExamples

use igraph::misc;
use std::{cell::RefCell, ops::ControlFlow, rc::Rc};

let log = Rc::new(RefCell::new(String::new()));
let sink = Rc::clone(&log);
let _guard = misc::set_status_handler(move |msg| {
    sink.borrow_mut().push_str(msg);
    ControlFlow::Continue(())
});
misc::status("loading; ")?;
misc::status("done")?;
assert_eq!(*log.borrow(), "loading; done");