pub struct Spinner {
pub spinner: Spinners,
/* private fields */
}Expand description
Main spinner struct
This holds all the information for the actual spinners
Fields§
§spinner: SpinnersThe enum variant used in this spinner
Implementations§
Source§impl Spinner
impl Spinner
Sourcepub fn start(&mut self)
pub fn start(&mut self)
Start the spinner
Explained more in depth in the Spinner::new function.
Sourcepub fn stop(&mut self) -> Option<SendError<Event>>
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();Sourcepub fn stop_with_message<S: Display>(&mut self, message: S)
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!");Sourcepub fn stop_with_symbol<S: Display>(&mut self, symbol: S)
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('✓');Sourcepub fn set_interval(&mut self, interval: u64)
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();Sourcepub fn set_message<S: Display>(&mut self, message: S)
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();Sourcepub fn set_spinner(&mut self, spinner: Spinners)
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));
}