Struct git_repository::progress::tree::Item
source · pub struct Item { /* private fields */ }
progress-tree
only.Expand description
A Tree
represents an element of the progress tree.
It can be used to set progress and send messages.
let tree = prodash::tree::Root::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_with_id("sub-task 1", *b"TSK2");
sub_progress.init(None, None);
sub_progress.set(5);
sub_progress.fail("couldn't finish");
Implementations§
source§impl Item
impl Item
sourcepub fn init(&mut self, max: Option<usize>, unit: Option<Unit>)
pub fn init(&mut self, max: Option<usize>, unit: Option<Unit>)
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.
sourcepub fn set_name(&mut self, name: impl Into<String>)
pub fn set_name(&mut self, name: impl Into<String>)
Set the name of this task’s progress to the given name
.
sourcepub fn max(&self) -> Option<usize>
pub fn max(&self) -> Option<usize>
Returns the maximum about of items we expect, as provided with the init(…)
call
sourcepub fn set_max(&mut self, max: Option<usize>) -> Option<usize>
pub fn set_max(&mut self, max: Option<usize>) -> Option<usize>
Set the maximum value to max
and return the old maximum value.
sourcepub fn set(&mut self, step: usize)
pub fn set(&mut self, step: usize)
Set the current progress to the given step
.
Note: that this call has no effect unless init(…)
was called before.
sourcepub fn inc_by(&mut self, step: usize)
pub fn inc_by(&mut self, step: usize)
Increment the current progress by the given step
.
Note: that this call has no effect unless init(…)
was called before.
sourcepub fn inc(&mut self)
pub fn inc(&mut self)
Increment the current progress by one.
Note: that this call has no effect unless init(…)
was called before.
sourcepub fn blocked(&mut self, reason: &'static str, eta: Option<SystemTime>)
pub fn blocked(&mut self, reason: &'static str, eta: Option<SystemTime>)
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 halted-state is undone next time tree::Item::running(…)
is called.
sourcepub fn halted(&mut self, reason: &'static str, eta: Option<SystemTime>)
pub fn halted(&mut self, reason: &'static str, eta: Option<SystemTime>)
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::running(…)
is called.
sourcepub fn running(&mut self)
pub fn running(&mut self)
Call to indicate that progress is back in running state, which should be called after the reason for
calling blocked()
or halted()
has passed.
sourcepub fn add_child(&mut self, name: impl Into<String>) -> Item
pub fn add_child(&mut self, name: impl Into<String>) -> Item
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.
sourcepub fn add_child_with_id(&mut self, name: impl Into<String>, id: [u8; 4]) -> Item
pub fn add_child_with_id(&mut self, name: impl Into<String>, id: [u8; 4]) -> Item
Adds a new child Tree
, whose parent is this instance, with the given name
and id
.
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.
sourcepub fn message(&mut self, level: MessageLevel, message: impl Into<String>)
pub fn message(&mut self, level: MessageLevel, message: impl Into<String>)
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.
Trait Implementations§
source§impl Progress for Item
impl Progress for Item
§type SubProgress = Item
type SubProgress = Item
add_child()
.source§fn add_child(
&mut self,
name: impl Into<String>
) -> <Item as Progress>::SubProgress
fn add_child( &mut self, name: impl Into<String> ) -> <Item as Progress>::SubProgress
name
. Read moresource§fn add_child_with_id(
&mut self,
name: impl Into<String>,
id: [u8; 4]
) -> <Item as Progress>::SubProgress
fn add_child_with_id( &mut self, name: impl Into<String>, id: [u8; 4] ) -> <Item as Progress>::SubProgress
source§fn init(&mut self, max: Option<usize>, unit: Option<Unit>)
fn init(&mut self, max: Option<usize>, unit: Option<Unit>)
source§fn set(&mut self, step: usize)
fn set(&mut self, step: usize)
step
. The cost of this call is negligible,
making manual throttling not necessary. Read moresource§fn max(&self) -> Option<usize>
fn max(&self) -> Option<usize>
init(…)
callsource§fn set_max(&mut self, max: Option<usize>) -> Option<usize>
fn set_max(&mut self, max: Option<usize>) -> Option<usize>
max
and return the old maximum value.source§fn inc_by(&mut self, step: usize)
fn inc_by(&mut self, step: usize)
step
.
The cost of this call is negligible, making manual throttling not necessary.source§fn set_name(&mut self, name: impl Into<String>)
fn set_name(&mut self, name: impl Into<String>)
add_child(…)
The progress is allowed to discard it.source§fn name(&self) -> Option<String>
fn name(&self) -> Option<String>
add_child(…)
The progress is allowed to not be named, thus there is no guarantee that a previously set names ‘sticks’.