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
impl Handle
Sourcepub fn inc(&self, delta: u64)
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}Sourcepub fn set_message<S: Into<String>>(&self, msg: S)
pub fn set_message<S: Into<String>>(&self, msg: S)
Set the caption.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Handle
impl RefUnwindSafe for Handle
impl Send for Handle
impl Sync for Handle
impl Unpin for Handle
impl UnsafeUnpin for Handle
impl UnwindSafe for Handle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more