Struct throbber::Throbber[][src]

pub struct Throbber { /* fields omitted */ }

Representation of a throbber animation. It can strart, succeed, fail or end at any point.

Note that a call to end() takes ownership of the struct and drops it, as such it should be called to completely remove the throbber animtion object. If you want to start another animation afterwards, you have to create a new Throbber object. This is done because multiple calls to start do not actually create multiple threads, instead a call to a finish function (like succeed()) simply parks the thread and a following start() call unparks that thread again. As such, a call to end() kills the thread entirely. If you want to just stop the animation, but potentially start it again later on, use finish() instead.

Examples

use throbber::Throbber;
use std::thread;
use std::time::Duration;

let mut throbber = Throbber::new()
    .message("calculating stuff".to_string())
    .interval(Duration::from_millis(50))
    .frames(&throbber::ROTATE_F);

throbber.start();

// do stuff
thread::sleep(Duration::from_secs(5));

throbber.success("calculation successful".to_string());
throbber.end();

Implementations

impl Throbber[src]

pub fn new() -> Self[src]

Creates a new Throbber object.

pub fn message(self, msg: String) -> Self[src]

Sets the message that’s supposed to print.

This does nothing if start() was called before. To change the message after start() was called, use change_message instead.

pub fn interval(self, interval: Duration) -> Self[src]

Sets the interval in which the animation frames are supposed to print.

This does nothing if start() was called before. To change the interval after start() was called, use change_interval instead.

pub fn frames(self, frames: &'static [&'static str]) -> Self[src]

Sets the animation frames that are supposed to print.

This does nothing if start() was called before. To change the animation frames after start() was called, use change_frames instead.

pub fn change_message(&mut self, msg: String)[src]

Changes the message that’s supposed to print.toml

Unlike message, this will work both before and after start() was called.

pub fn change_interval(&mut self, interval: Duration)[src]

Changes the interval in which the animation frames are supposed to print.

Unlike interval, this will work both before and after start() was called.

pub fn change_frames(&mut self, frames: &'static [&'static str])[src]

Changes the animation frames that are supposed to print.

Unlike frames, this will work both before and after start() was called.

pub fn start(&mut self)[src]

Starts the animation.

If this is the first call to start(), a new thread gets created to play the animation. Otherwise the thread that already exists gets unparked and starts the animation again.

pub fn start_with_msg(&mut self, msg: String)[src]

Starts the animation with the specified msg.

Equivalent to throbber.change_message(msg); throbber.start();.

pub fn finish(&mut self)[src]

Stops the current animation, leaving a blank line.

pub fn success(&mut self, msg: String)[src]

Stops the current animation and prints msg as a success message.

pub fn fail(&mut self, msg: String)[src]

Stops the current animation and prints msg as a fail message.

pub fn end(self)[src]

Encds the animation thread and drops the throbber object. If you want to stop the animation without dropping the throbber object, use finish instead.

Auto Trait Implementations

impl !RefUnwindSafe for Throbber

impl Send for Throbber

impl !Sync for Throbber

impl Unpin for Throbber

impl !UnwindSafe for Throbber

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.