Crate transition[][src]

This crate allows to programmatically control LED light - blink(1). The purpose is to be able to show the status of your task by "wrapping" all it's execution between calls to this library.

While your code is executing, the LED transition between two specified colors indicating "pending" state. After your code finishes execution, you can notify the LED about the status of your task, changing it's light to one of two colors - depending on the status of your code.

Example

use transition::{Transition, Led};
use std::error::Error;
use std::thread;
use std::time::Duration;

fn main() -> Result<(), Box<dyn Error>> {
    let notifier = Transition::new(&[Led::Blue, Led::Blank])? // pending state
        .on_success(&Led::Green)
        .on_failure(&Led::Red)
        .start()?;

    // your code here, e.g.:
    thread::sleep(Duration::from_secs(2));

    notifier.notify_success(); // or notifier.notify_failure();
    // LED changes color to the one specified for success
    Ok(())
}

Structs

Notifier

Allows to control blinking of the LED after the transition starts.

Transition

Main structure. Represents colors of task state (pending, successfull, failed). Allows to start the transition.

Enums

Led

Represents the color of the Led.

TransitionErr

Error descriping issue with the transition.