Struct prodash::tree::Item[][src]

pub struct Item { /* fields omitted */ }

A Tree represents an element of the progress tree.

It can be used to set progress and send messages.

let tree = prodash::Tree::new();
let mut progress = tree.add_child("task 1");

progress.init(Some(10), Some("elements".into()));
for p in 0..10 {
    progress.set(p);
}
progress.done("great success");
let mut  sub_progress = progress.add_child("sub-task 1");
sub_progress.init(None, None);
sub_progress.set(5);
sub_progress.fail("couldn't finish");

Implementations

impl Item[src]

pub fn init(&mut self, max: Option<Step>, unit: Option<Unit>)[src]

Initialize the Item for receiving progress information.

If max is Some(…), it will be treated as upper bound. When progress is set(…) it should not exceed the given maximum. If max is None, the progress is unbounded. Use this if the amount of work cannot accurately be determined.

If unit is Some(…), it is used for display purposes only. It should be using the plural.

If this method is never called, this Item will serve as organizational unit, useful to add more structure to the progress tree.

Note that this method can be called multiple times, changing the bounded-ness and unit at will.

pub fn set_name(&mut self, name: impl Into<String>)[src]

Set the name of this task’s progress to the given name.

pub fn name(&self) -> Option<String>[src]

Get the name of this task’s progress

pub fn step(&self) -> Option<Step>[src]

Returns the current step, as controlled by inc*(…) calls

pub fn max(&self) -> Option<Step>[src]

Returns the maximum about of items we expect, as provided with the init(…) call

pub fn unit(&self) -> Option<Unit>[src]

Returns the (cloned) unit associated with this Progress

pub fn set(&mut self, step: Step)[src]

Set the current progress to the given step.

Note: that this call has no effect unless init(…) was called before.

pub fn inc_by(&mut self, step: Step)[src]

Increment the current progress by the given step.

Note: that this call has no effect unless init(…) was called before.

pub fn inc(&mut self)[src]

Increment the current progress by one.

Note: that this call has no effect unless init(…) was called before.

pub fn blocked(&mut self, reason: &'static str, eta: Option<SystemTime>)[src]

Call to indicate that progress cannot be indicated, and that the task cannot be interrupted. Use this, as opposed to halted(…), if a non-interruptable call is about to be made without support for any progress indication.

If eta is Some(…), it specifies the time at which this task is expected to make progress again.

The blocked-state is undone next time tree::Item::set(…) is called.

pub fn halted(&mut self, reason: &'static str, eta: Option<SystemTime>)[src]

Call to indicate that progress cannot be indicated, even though the task can be interrupted. Use this, as opposed to blocked(…), if an interruptable call is about to be made without support for any progress indication.

If eta is Some(…), it specifies the time at which this task is expected to make progress again.

The halted-state is undone next time tree::Item::set(…) is called.

pub fn add_child(&mut self, name: impl Into<String>) -> Item[src]

Adds a new child Tree, whose parent is this instance, with the given name.

Important: The depth of the hierarchy is limited to tree::Key::max_level. Exceeding the level will be ignored, and new tasks will be added to this instance’s level instead.

pub fn message(&mut self, level: MessageLevel, message: impl Into<String>)[src]

Create a message of the given level and store it with the progress tree.

Use this to provide additional,human-readable information about the progress made, including indicating success or failure.

pub fn done(&mut self, message: impl Into<String>)[src]

Create a message indicating the task is done

pub fn fail(&mut self, message: impl Into<String>)[src]

Create a message indicating the task failed

pub fn info(&mut self, message: impl Into<String>)[src]

Create a message providing additional information about the progress thus far.

Trait Implementations

impl Debug for Item[src]

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

Formats the value using the given formatter. Read more

impl Drop for Item[src]

fn drop(&mut self)[src]

Executes the destructor for this type. Read more

impl Progress for Item[src]

type SubProgress = Item

The type of progress returned by add_child().

fn add_child(&mut self, name: impl Into<String>) -> Self::SubProgress[src]

Adds a new child, whose parent is this instance, with the given name. Read more

fn init(&mut self, max: Option<usize>, unit: Option<Unit>)[src]

Initialize the Item for receiving progress information. Read more

fn set(&mut self, step: usize)[src]

Set the current progress to the given step. The cost of this call is negligible, making manual throttling not necessary. Read more

fn unit(&self) -> Option<Unit>[src]

Returns the (cloned) unit associated with this Progress

fn max(&self) -> Option<usize>[src]

Returns the maximum about of items we expect, as provided with the init(…) call

fn step(&self) -> usize[src]

Returns the current step, as controlled by inc*(…) calls

fn inc_by(&mut self, step: usize)[src]

Increment the current progress to the given step. The cost of this call is negligible, making manual throttling not necessary. Read more

fn set_name(&mut self, name: impl Into<String>)[src]

Set the name of the instance, altering the value given when crating it with add_child(…) The progress is allowed to discard it. Read more

fn name(&self) -> Option<String>[src]

Get the name of the instance as given when creating it with add_child(…) The progress is allowed to not be named, thus there is no guarantee that a previously set names ‘sticks’. Read more

fn message(&mut self, level: MessageLevel, message: impl Into<String>)[src]

Create a message of the given level and store it with the progress tree. Read more

fn inc(&mut self)[src]

Increment the current progress to the given 1. The cost of this call is negligible, making manual throttling not necessary. Read more

fn info(&mut self, message: impl Into<String>)[src]

Create a message providing additional information about the progress thus far.

fn done(&mut self, message: impl Into<String>)[src]

Create a message indicating the task is done successfully

fn fail(&mut self, message: impl Into<String>)[src]

Create a message indicating the task failed

fn show_throughput(&mut self, start: Instant)[src]

A shorthand to print throughput information

fn show_throughput_with(&mut self, start: Instant, step: Step, unit: Unit)[src]

A shorthand to print throughput information, with the given step and unit

Auto Trait Implementations

impl !RefUnwindSafe for Item

impl Send for Item

impl Sync for Item

impl Unpin for Item

impl !UnwindSafe for Item

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.