Spinner

Struct Spinner 

Source
pub struct Spinner {
    pub spinner: Spinners,
    /* private fields */
}
Expand description

Main spinner struct

This holds all the information for the actual spinners

Fields§

§spinner: Spinners

The enum variant used in this spinner

Implementations§

Source§

impl Spinner

Source

pub fn new<T, S>(spinner: T, message: S) -> Self
where T: Into<Spinners> + Copy, S: Display,

Create a new spinner along with a message

§Examples
§Basic Usage:
use spinners_rs::{Spinners, Spinner};

let mut sp = Spinner::new(Spinners::Dots, "Doing some cool things...");
sp.start();
§No Message:
use spinners_rs::{Spinners, Spinner};

let mut sp: Spinner = Spinners::Dots.into();
sp.start();
Source

pub fn start(&mut self)

Start the spinner

Explained more in depth in the Spinner::new function.

Source

pub fn stop(&mut self) -> Option<SendError<Event>>

Stops the spinner from running

Alternatively you can use the Spinner::stop_with_message or Spinner::stop_with_symbol function.

§Example:
use spinners_rs::{Spinners, Spinner};
use std::{thread, time::Duration};

let mut sp: Spinner = Spinners::Dots.into();
sp.start();

thread::sleep(Duration::from_millis(1000));

sp.stop();
Source

pub fn stop_with_message<S: Display>(&mut self, message: S)

Stops the spinner and replaces it with the given message

§Example:
use spinners_rs::{Spinners, Spinner};
use std::{thread, time::Duration};

let mut sp: Spinner = Spinners::Dots.into();
sp.start();

thread::sleep(Duration::from_millis(1000));

sp.stop_with_message("We've finished that thing!");
Source

pub fn stop_with_symbol<S: Display>(&mut self, symbol: S)

Stops the spinner and replaces the current frame with the given symbol

§Example:
use spinners_rs::{Spinners, Spinner};
use std::{thread, time::Duration};

let mut sp: Spinner = Spinners::Dots.into();
sp.start();

thread::sleep(Duration::from_millis(1000));

sp.stop_with_symbol('✓');
Source

pub fn set_interval(&mut self, interval: u64)

Updates the frame interval

This changes how fast each frame comes up

This can be changed before the spinner is started or after

§Example:
use spinners_rs::{Spinners, Spinner};
use std::{thread, time::Duration};

let mut sp: Spinner = Spinners::Dots.into();
sp.start();

// Will run through one iteration of frames
thread::sleep(Duration::from_millis(1000));

sp.set_interval(500);

// Will now run through two iterations of the frames
thread::sleep(Duration::from_millis(1000));

sp.stop();
Source

pub fn set_message<S: Display>(&mut self, message: S)

Sets the message to display

Similar to Spinner::set_interval, this can be set before or after a spinner is started

§Example :
use spinners_rs::{Spinners, Spinner};
use std::{thread, time::Duration};

let mut sp: Spinner = Spinners::Dots.into();
sp.start();

thread::sleep(Duration::from_millis(1000));

sp.set_message("Doing some cool things...");

thread::sleep(Duration::from_millis(1000));

sp.stop();
Source

pub fn set_spinner(&mut self, spinner: Spinners)

Changes the spinner mid run

This will change the spinner to the given one, allowing you to change the frames shown, on the current spinner without allocating a new variable and memory.

§Example:
use std::{thread, time::Duration};

use spinners_rs::{Spinner, Spinners};

use strum::IntoEnumIterator;

let sps = Spinners::iter().collect::<Vec<Spinners>>();
let len = sps.len();
let sp = sps.get(0).unwrap();
let mut spinner: Spinner = (*sp).into();
spinner.start();

for (i, sp) in sps[1..].iter().enumerate() {
    spinner.set_spinner(*sp);

    thread::sleep(Duration::from_millis(1000));
}
Source

pub fn get_name(&self) -> String

Gets the spinner name capitalizes the first letter.

§Example:
use spinners_rs::{Spinners, Spinner};

let sp: Spinner = Spinners::Dots.into();
assert_eq!(sp.get_name(), "Dots");

Trait Implementations§

Source§

impl Clone for Spinner

Source§

fn clone(&self) -> Spinner

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Spinner

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Spinner

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl From<Spinners> for Spinner

Source§

fn from(spinner: Spinners) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.