Spinner

Struct Spinner 

Source
pub struct Spinner<S> { /* private fields */ }
Expand description

A Spinach spinner

Represents a spinner that can be used to show progress or activity.

§Examples

use spinach::Spinner;

let spinner = Spinner::new("Loading...").start();
// Perform some tasks
spinner.text("gg!").success();

Implementations§

Source§

impl<S> Spinner<S>

Source

pub fn color(&self, color: Color) -> &Self

Sets the color of the spinner.

§Examples
use spinach::{Spinner, Color};

let spinner = Spinner::new("workin'...").color(Color::Blue).start();
Examples found in repository?
examples/cooking.rs (line 9)
7fn main() {
8    let spinner = Spinner::new("Cutting spinaches")
9        .color(Green)
10        .frames_duration(30)
11        .start();
12
13    sleep(Duration::from_secs(1));
14    spinner.text("Cutting tomatoes").update();
15
16    sleep(Duration::from_secs(1));
17    spinner.text("Vegetables cut").symbol("🔪").stop();
18
19    let spinner = Spinner::new("Cooking vegetables")
20        .color(Green)
21        .frames_duration(30)
22        .start();
23
24    sleep(Duration::from_secs(1));
25    spinner.text("Vegetables cooked").symbol("🍲").stop();
26
27    sleep(Duration::from_secs(1));
28}
Source

pub fn text(&self, text: &str) -> &Self

Sets the text displayed alongside the spinner.

§Examples
use spinach::Spinner;

let spinner = Spinner::new("workin'...").start();
Examples found in repository?
examples/cooking.rs (line 14)
7fn main() {
8    let spinner = Spinner::new("Cutting spinaches")
9        .color(Green)
10        .frames_duration(30)
11        .start();
12
13    sleep(Duration::from_secs(1));
14    spinner.text("Cutting tomatoes").update();
15
16    sleep(Duration::from_secs(1));
17    spinner.text("Vegetables cut").symbol("🔪").stop();
18
19    let spinner = Spinner::new("Cooking vegetables")
20        .color(Green)
21        .frames_duration(30)
22        .start();
23
24    sleep(Duration::from_secs(1));
25    spinner.text("Vegetables cooked").symbol("🍲").stop();
26
27    sleep(Duration::from_secs(1));
28}
Source

pub fn symbols(&self, symbols: Vec<&'static str>) -> &Self

Sets the symbols used for the spinner animation.

§Examples
use spinach::Spinner;

let spinner = Spinner::new("workin'...").symbols(vec!["◐", "◓", "◑", "◒"]).start();
Source

pub fn symbol(&self, symbol: &'static str) -> &Self

Sets a single symbol for the spinner animation. This is useful when you want to set a final symbol, for example.

§Examples
use spinach::Spinner;

let spinner = Spinner::new("workin'...").start().text("done!").symbol("✔").stop();
Examples found in repository?
examples/cooking.rs (line 17)
7fn main() {
8    let spinner = Spinner::new("Cutting spinaches")
9        .color(Green)
10        .frames_duration(30)
11        .start();
12
13    sleep(Duration::from_secs(1));
14    spinner.text("Cutting tomatoes").update();
15
16    sleep(Duration::from_secs(1));
17    spinner.text("Vegetables cut").symbol("🔪").stop();
18
19    let spinner = Spinner::new("Cooking vegetables")
20        .color(Green)
21        .frames_duration(30)
22        .start();
23
24    sleep(Duration::from_secs(1));
25    spinner.text("Vegetables cooked").symbol("🍲").stop();
26
27    sleep(Duration::from_secs(1));
28}
Source

pub fn frames_duration(&self, ms: u64) -> &Self

Sets the duration of each frame in the spinner animation.

§Examples
use spinach::Spinner;

let spinner = Spinner::new("workin'...").frames_duration(40).start();
Examples found in repository?
examples/cooking.rs (line 10)
7fn main() {
8    let spinner = Spinner::new("Cutting spinaches")
9        .color(Green)
10        .frames_duration(30)
11        .start();
12
13    sleep(Duration::from_secs(1));
14    spinner.text("Cutting tomatoes").update();
15
16    sleep(Duration::from_secs(1));
17    spinner.text("Vegetables cut").symbol("🔪").stop();
18
19    let spinner = Spinner::new("Cooking vegetables")
20        .color(Green)
21        .frames_duration(30)
22        .start();
23
24    sleep(Duration::from_secs(1));
25    spinner.text("Vegetables cooked").symbol("🍲").stop();
26
27    sleep(Duration::from_secs(1));
28}
Source§

impl Spinner<Stopped>

Source

pub fn new(text: &str) -> Self

Creates a new spinner.

§Examples
use spinach::Spinner;

let spinner = Spinner::new("let's go...").start();
Examples found in repository?
examples/cooking.rs (line 8)
7fn main() {
8    let spinner = Spinner::new("Cutting spinaches")
9        .color(Green)
10        .frames_duration(30)
11        .start();
12
13    sleep(Duration::from_secs(1));
14    spinner.text("Cutting tomatoes").update();
15
16    sleep(Duration::from_secs(1));
17    spinner.text("Vegetables cut").symbol("🔪").stop();
18
19    let spinner = Spinner::new("Cooking vegetables")
20        .color(Green)
21        .frames_duration(30)
22        .start();
23
24    sleep(Duration::from_secs(1));
25    spinner.text("Vegetables cooked").symbol("🍲").stop();
26
27    sleep(Duration::from_secs(1));
28}
Source

pub fn start(&self) -> Spinner<Running>

Starts the spinner.

§Examples
use spinach::Spinner;

let spinner = Spinner::new("let's go...").start();
Examples found in repository?
examples/cooking.rs (line 11)
7fn main() {
8    let spinner = Spinner::new("Cutting spinaches")
9        .color(Green)
10        .frames_duration(30)
11        .start();
12
13    sleep(Duration::from_secs(1));
14    spinner.text("Cutting tomatoes").update();
15
16    sleep(Duration::from_secs(1));
17    spinner.text("Vegetables cut").symbol("🔪").stop();
18
19    let spinner = Spinner::new("Cooking vegetables")
20        .color(Green)
21        .frames_duration(30)
22        .start();
23
24    sleep(Duration::from_secs(1));
25    spinner.text("Vegetables cooked").symbol("🍲").stop();
26
27    sleep(Duration::from_secs(1));
28}
Source§

impl Spinner<Running>

Source

pub fn update(&self) -> &Self

Updates the spinner with the current update state.

§Examples
use spinach::Spinner;

let spinner = Spinner::new("Doing something...").start();
// Perform some tasks
spinner.text("Doing something else...").update();
Examples found in repository?
examples/cooking.rs (line 14)
7fn main() {
8    let spinner = Spinner::new("Cutting spinaches")
9        .color(Green)
10        .frames_duration(30)
11        .start();
12
13    sleep(Duration::from_secs(1));
14    spinner.text("Cutting tomatoes").update();
15
16    sleep(Duration::from_secs(1));
17    spinner.text("Vegetables cut").symbol("🔪").stop();
18
19    let spinner = Spinner::new("Cooking vegetables")
20        .color(Green)
21        .frames_duration(30)
22        .start();
23
24    sleep(Duration::from_secs(1));
25    spinner.text("Vegetables cooked").symbol("🍲").stop();
26
27    sleep(Duration::from_secs(1));
28}
Source

pub fn stop(&self)

Stops the spinner.

§Examples
use spinach::Spinner;

let spinner = Spinner::new("Doing something...").start();
// Perform some tasks
spinner.text("done!").stop();
Examples found in repository?
examples/cooking.rs (line 17)
7fn main() {
8    let spinner = Spinner::new("Cutting spinaches")
9        .color(Green)
10        .frames_duration(30)
11        .start();
12
13    sleep(Duration::from_secs(1));
14    spinner.text("Cutting tomatoes").update();
15
16    sleep(Duration::from_secs(1));
17    spinner.text("Vegetables cut").symbol("🔪").stop();
18
19    let spinner = Spinner::new("Cooking vegetables")
20        .color(Green)
21        .frames_duration(30)
22        .start();
23
24    sleep(Duration::from_secs(1));
25    spinner.text("Vegetables cooked").symbol("🍲").stop();
26
27    sleep(Duration::from_secs(1));
28}
Source

pub fn success(&self)

Stops the spinner with a pre-configured success indication. Sets the symbol and color.

§Examples
use spinach::Spinner;

let spinner = Spinner::new("Doing something...").start();
// Perform some task that succeeds
spinner.text("done!").success();
Source

pub fn failure(&self)

Stops the spinner with a pre-configured failure indication. Sets the symbol and color.

§Examples
use spinach::Spinner;

let spinner = Spinner::new("Doing something...").start();
// Perform some task that fails
spinner.text("oops").failure();
Source

pub fn warn(&self)

Stops the spinner with a pre-configured warning indication. Sets the symbol and color.

§Examples
use spinach::Spinner;

let spinner = Spinner::new("Doing something...").start();
// Perform some task with unexpected results
spinner.text("wait, what?").warn();

Trait Implementations§

Source§

impl<S: Clone> Clone for Spinner<S>

Source§

fn clone(&self) -> Spinner<S>

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<S: Debug> Debug for Spinner<S>

Source§

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

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

impl<S: Default> Default for Spinner<S>

Source§

fn default() -> Spinner<S>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S> !Freeze for Spinner<S>

§

impl<S> !RefUnwindSafe for Spinner<S>

§

impl<S> Send for Spinner<S>
where S: Send,

§

impl<S> !Sync for Spinner<S>

§

impl<S> Unpin for Spinner<S>
where S: Unpin,

§

impl<S> UnwindSafe for Spinner<S>
where S: UnwindSafe,

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.