Struct termprogress::spinner::Spin

source ·
pub struct Spin<T: ?Sized = Stdout> { /* private fields */ }
Expand description

A single character spinner with optional title that can be told to spin whenever it wants. It implements Spinner trait, and is the default spinner.

The spinner takes up a line, and renders it’s spinner on the end of its title. Calling the Spinner::bump() function will cause the character sequence to advance.

Usage

To use the spinner you can provide it a Wheel (see [wheel] module), or it implements the Default trait, creating a traditional looking spinner (|/-\)

let mut spin = Spin::default(); //Default new spinner without a title.

How it looks

It renders in the terminal like: This is a spinner /

Thread Syncsafety

This type is safely Sync (where T is), the behaviour is defined to prevent overlapping writes to T. Though it is advised to not render a Spin from more than a single thread, you still safely can.

A display operation on one thread will cause any other threads attempting on to silently and safely abort their display attempt before anything is written to output.

Implementations§

source§

impl Spin

source

pub fn with_title_default(title: &str, whl: Wheel) -> Self

Create a new spinner with title and wheel writing to stdout.

To give it the default wheel, you can pass whl Default::default() to use the default one.

source

pub fn new_default(whl: Wheel) -> Self

Create a new blank spinner with a wheel writing to stdout.

Example
 Spin::new_default(Default::default()); // Create a spinner with the default wheel ('|/-\') that writes to stdout.
source§

impl<T> Spin<T>

source

pub fn into_inner(self) -> T

Return the backing write object

source§

impl<T: ?Sized> Spin<T>

source

pub fn inner_mut(&mut self) -> &mut T

Get a mutable reference to the inner object

source

pub fn inner(&self) -> Option<AtomicRef<'_, T>>

Get a shared reference to the inner object

Returns

None is returned if a display operation is currently in progress on another thread.

Operation suspension

As long as the returned reference lives, all display operations will fail silently, on this thread and any other. This method should be avoided in favour of &*inner_mut() when exclusive ownership is avaliable.

source§

impl<T: Write> Spin<T>

source

pub fn with_title(output: T, title: &str, whl: Wheel) -> Self

Create a new spinner with title and wheel writing to output.

To give it the default wheel, you can pass whl Default::default() to use the default one.

source

pub fn new(output: T, whl: Wheel) -> Self

Create a new blank spinner with a wheel writing to output.

Example
 Spin::new(std::io::stdout(), Default::default()); // Create a spinner with the default wheel ('|/-\') that writes to stdout.
source

pub fn complete(self) -> Result<()>

Consume the spinner and complete it. Removes the spin character.

source

pub fn complete_with(self, msg: &str) -> Result<()>

Consume the spinner and complete it with a message. Removes the spin character and then prints the message.

Trait Implementations§

source§

impl Default for Spin

source§

fn default() -> Self

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

impl<T: ?Sized + Write> Display for Spin<T>

source§

fn refresh(&self)

Refresh the display
source§

fn blank(&self)

Blank the display
source§

fn get_title(&self) -> &str

Get the title for this display
source§

fn set_title(&mut self, from: &str)

Set the title for this display
source§

fn update_dimensions(&mut self, _: usize)

Update the max size if needed
source§

fn println(&self, string: &str)

Blank then print a line, and redisplay.
source§

fn eprintln(&self, string: &str)

Blank then print a line std stderr, and redisplay.
source§

impl<T: ?Sized + Write> Spinner for Spin<T>

source§

fn bump(&mut self)

Cause the spinner to increment once.
source§

impl<T: Write> WithTitle for Spin<T>

source§

fn with_title(self, t: impl AsRef<str>) -> Self

Add a title to this indicator.
source§

fn add_title(&mut self, t: impl AsRef<str>)

Add a title to this indicator.
source§

fn update(&mut self)

source§

fn complete(self)

Auto Trait Implementations§

§

impl<T = Stdout> !RefUnwindSafe for Spin<T>

§

impl<T: ?Sized> Send for Spin<T>where T: Send,

§

impl<T: ?Sized> Sync for Spin<T>where T: Send + Sync,

§

impl<T: ?Sized> Unpin for Spin<T>where T: Unpin,

§

impl<T: ?Sized> UnwindSafe for Spin<T>where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.