Skip to content

Commit

Permalink
Implement Root trait for tree::Root
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 10, 2020
1 parent cdabdce commit ec5c673
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ pub mod messages;
pub mod progress;

mod traits;
pub use traits::{Progress, Root};

mod throughput;
pub use crate::throughput::Throughput;

pub use traits::Progress;

#[cfg(not(feature = "log-renderer"))]
mod log {
/// Stub
Expand Down
15 changes: 8 additions & 7 deletions src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{messages::MessageLevel, Unit};
use crate::{messages::MessageLevel, progress, Unit};
use std::time::Instant;

pub trait Progress {
Expand Down Expand Up @@ -78,18 +78,19 @@ pub trait Progress {

use crate::messages::{Message, MessageCopyState};

trait Root {
/// The top level of a progress task hiearchy, with `progress::Task`s identified with `progress::Key`s
pub trait Root {
/// Returns the maximum amount of messages we can keep before overwriting older ones.
fn messages_capacity(&self) -> usize;

/// Returns the current amount of tasks underneath the root, transitively.
/// **Note** that this is at most a guess as tasks can be added and removed in parallel.
fn num_tasks(&self) -> usize;
//
// /// Copy the entire progress tree into the given `out` vector, so that
// /// it can be traversed from beginning to end in order of hierarchy.
// /// The `out` vec will be cleared automatically.
// fn sorted_snapshot(&self, out: &mut Vec<(progress::Key, progress::Task)>);

/// Copy the entire progress tree into the given `out` vector, so that
/// it can be traversed from beginning to end in order of hierarchy.
/// The `out` vec will be cleared automatically.
fn sorted_snapshot(&self, out: &mut Vec<(progress::Key, progress::Task)>);

/// Copy all messages from the internal ring buffer into the given `out`
/// vector. Messages are ordered from oldest to newest.
Expand Down
22 changes: 22 additions & 0 deletions src/tree/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,25 @@ impl From<Options> for Root {
}
}
}

impl crate::Root for Root {
fn messages_capacity(&self) -> usize {
self.messages_capacity()
}

fn num_tasks(&self) -> usize {
self.num_tasks()
}

fn sorted_snapshot(&self, out: &mut Vec<(Key, Task)>) {
self.sorted_snapshot(out)
}

fn copy_messages(&self, out: &mut Vec<Message>) {
self.copy_messages(out)
}

fn copy_new_messages(&self, out: &mut Vec<Message>, prev: Option<MessageCopyState>) -> MessageCopyState {
self.copy_new_messages(out, prev)
}
}

0 comments on commit ec5c673

Please sign in to comment.