Skip to main content

Handle

Struct Handle 

Source
pub struct Handle { /* private fields */ }
Expand description

A cheap, clonable updater obtained from Loader::handle. Safe to send to and share across threads.

Implementations§

Source§

impl Handle

Source

pub fn inc(&self, delta: u64)

Advance the position by delta.

Examples found in repository?
examples/loader.rs (line 43)
21fn main() {
22    match std::env::args().nth(1).as_deref() {
23        Some("iter") => {
24            for _ in (0..100).inkling() {
25                work(20);
26            }
27        }
28        Some("spinner") => {
29            let loader = Loader::spinner();
30            loader.set_message("Doing something mysterious");
31            work(2500);
32            loader.finish();
33        }
34        Some("threads") => {
35            let loader = Loader::new(120);
36            loader.set_message("Four workers, one dragon");
37            thread::scope(|s| {
38                for _ in 0..4 {
39                    let handle = loader.handle();
40                    s.spawn(move || {
41                        for _ in 0..30 {
42                            work(30);
43                            handle.inc(1);
44                        }
45                    });
46                }
47            });
48            loader.finish();
49        }
50        Some("rainbow") => {
51            let loader = Loader::builder()
52                .total(100)
53                .style(inkling::render::Style::rainbow())
54                .message("Tasting the rainbow")
55                .start();
56            for _ in 0..100 {
57                work(20);
58                loader.inc(1);
59            }
60            loader.finish();
61        }
62        _ => {
63            let total: u64 = 100;
64            let loader = Loader::new(total);
65            loader.set_message("Summoning the dragon");
66            for _ in 0..total {
67                work(20);
68                loader.inc(1);
69            }
70            loader.finish();
71        }
72    }
73}
Source

pub fn set(&self, pos: u64)

Set the absolute position.

Source

pub fn set_message<S: Into<String>>(&self, msg: S)

Set the caption.

Source

pub fn position(&self) -> u64

The current position.

Trait Implementations§

Source§

impl Clone for Handle

Source§

fn clone(&self) -> Handle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more

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.