pub struct SBState { /* private fields */ }Implementations§
Source§impl SBState
impl SBState
Sourcepub fn new(config: SBStateConfig) -> Self
pub fn new(config: SBStateConfig) -> Self
Examples found in repository?
More examples
examples/demo.rs (lines 6-10)
5fn main() {
6 let state = SBState::new(SBStateConfig {
7 silent: false,
8 task_name_width: TaskNameWidth::ExactRatio(0.25),
9 ..Default::default()
10 });
11
12 // The handles for these tasks are immediately dropped, so we automatically remove them.
13 // Except for error/info, which we display for a little while before removing automatically.
14 {
15 {
16 let task_id = state.add_task("finished task", Status::Finished);
17 state.add_subtask(&task_id, Status::Started);
18 }
19 let _ = state.add_task("error task", Status::Error);
20 let _ = state.add_task("started task", Status::Started);
21 let _ = state.add_task("queued task", Status::Queued);
22 }
23
24 let mut tasks = (0..10)
25 .into_iter()
26 .map(|index| {
27 let state = state.clone();
28 std::thread::spawn(move || {
29 std::thread::sleep(Duration::from_secs(index));
30 let task_id = state.add_task(format!("Task {index}"), Status::Started);
31 std::thread::sleep(Duration::from_secs(index.min(3)));
32 let sub_tasks = (0..10)
33 .into_iter()
34 .map(|_| state.add_subtask(&task_id, Status::Started))
35 .collect::<Vec<_>>();
36
37 for sub_task_id in sub_tasks {
38 std::thread::sleep(Duration::from_secs((index + 1).min(3)));
39 state.update_subtask(&task_id, &sub_task_id, Status::Finished);
40 }
41
42 state.update_task(&task_id, Status::Finished);
43 })
44 })
45 .collect::<Vec<_>>();
46
47 tasks.push(std::thread::spawn({
48 let state = state.clone();
49 move || {
50 let task_id = state.add_task(format!("Task with no children"), Status::Started);
51 std::thread::sleep(Duration::from_secs(10));
52 state.update_task(&task_id, Status::Finished);
53 }
54 }));
55
56 tasks.push(std::thread::spawn(move || {
57 std::thread::sleep(Duration::from_secs(4));
58 state.info("Here's an informational message");
59 std::thread::sleep(Duration::from_secs(8));
60 state.info("Here's another one :)");
61 }));
62
63 for task in tasks {
64 task.join().unwrap();
65 }
66}pub fn error<S: ToString>(&self, display_name: S)
Sourcepub fn info<S: ToString>(&self, display_name: S)
pub fn info<S: ToString>(&self, display_name: S)
Examples found in repository?
examples/demo.rs (line 58)
5fn main() {
6 let state = SBState::new(SBStateConfig {
7 silent: false,
8 task_name_width: TaskNameWidth::ExactRatio(0.25),
9 ..Default::default()
10 });
11
12 // The handles for these tasks are immediately dropped, so we automatically remove them.
13 // Except for error/info, which we display for a little while before removing automatically.
14 {
15 {
16 let task_id = state.add_task("finished task", Status::Finished);
17 state.add_subtask(&task_id, Status::Started);
18 }
19 let _ = state.add_task("error task", Status::Error);
20 let _ = state.add_task("started task", Status::Started);
21 let _ = state.add_task("queued task", Status::Queued);
22 }
23
24 let mut tasks = (0..10)
25 .into_iter()
26 .map(|index| {
27 let state = state.clone();
28 std::thread::spawn(move || {
29 std::thread::sleep(Duration::from_secs(index));
30 let task_id = state.add_task(format!("Task {index}"), Status::Started);
31 std::thread::sleep(Duration::from_secs(index.min(3)));
32 let sub_tasks = (0..10)
33 .into_iter()
34 .map(|_| state.add_subtask(&task_id, Status::Started))
35 .collect::<Vec<_>>();
36
37 for sub_task_id in sub_tasks {
38 std::thread::sleep(Duration::from_secs((index + 1).min(3)));
39 state.update_subtask(&task_id, &sub_task_id, Status::Finished);
40 }
41
42 state.update_task(&task_id, Status::Finished);
43 })
44 })
45 .collect::<Vec<_>>();
46
47 tasks.push(std::thread::spawn({
48 let state = state.clone();
49 move || {
50 let task_id = state.add_task(format!("Task with no children"), Status::Started);
51 std::thread::sleep(Duration::from_secs(10));
52 state.update_task(&task_id, Status::Finished);
53 }
54 }));
55
56 tasks.push(std::thread::spawn(move || {
57 std::thread::sleep(Duration::from_secs(4));
58 state.info("Here's an informational message");
59 std::thread::sleep(Duration::from_secs(8));
60 state.info("Here's another one :)");
61 }));
62
63 for task in tasks {
64 task.join().unwrap();
65 }
66}Sourcepub fn add_task<S: ToString>(&self, display_name: S, status: Status) -> TaskId
pub fn add_task<S: ToString>(&self, display_name: S, status: Status) -> TaskId
Examples found in repository?
More examples
examples/demo.rs (line 16)
5fn main() {
6 let state = SBState::new(SBStateConfig {
7 silent: false,
8 task_name_width: TaskNameWidth::ExactRatio(0.25),
9 ..Default::default()
10 });
11
12 // The handles for these tasks are immediately dropped, so we automatically remove them.
13 // Except for error/info, which we display for a little while before removing automatically.
14 {
15 {
16 let task_id = state.add_task("finished task", Status::Finished);
17 state.add_subtask(&task_id, Status::Started);
18 }
19 let _ = state.add_task("error task", Status::Error);
20 let _ = state.add_task("started task", Status::Started);
21 let _ = state.add_task("queued task", Status::Queued);
22 }
23
24 let mut tasks = (0..10)
25 .into_iter()
26 .map(|index| {
27 let state = state.clone();
28 std::thread::spawn(move || {
29 std::thread::sleep(Duration::from_secs(index));
30 let task_id = state.add_task(format!("Task {index}"), Status::Started);
31 std::thread::sleep(Duration::from_secs(index.min(3)));
32 let sub_tasks = (0..10)
33 .into_iter()
34 .map(|_| state.add_subtask(&task_id, Status::Started))
35 .collect::<Vec<_>>();
36
37 for sub_task_id in sub_tasks {
38 std::thread::sleep(Duration::from_secs((index + 1).min(3)));
39 state.update_subtask(&task_id, &sub_task_id, Status::Finished);
40 }
41
42 state.update_task(&task_id, Status::Finished);
43 })
44 })
45 .collect::<Vec<_>>();
46
47 tasks.push(std::thread::spawn({
48 let state = state.clone();
49 move || {
50 let task_id = state.add_task(format!("Task with no children"), Status::Started);
51 std::thread::sleep(Duration::from_secs(10));
52 state.update_task(&task_id, Status::Finished);
53 }
54 }));
55
56 tasks.push(std::thread::spawn(move || {
57 std::thread::sleep(Duration::from_secs(4));
58 state.info("Here's an informational message");
59 std::thread::sleep(Duration::from_secs(8));
60 state.info("Here's another one :)");
61 }));
62
63 for task in tasks {
64 task.join().unwrap();
65 }
66}pub fn set_task_display_name(&self, task_id: &TaskId, display_name: String)
pub fn delete_task(&self, task_id: &TaskId)
Sourcepub fn update_task(&self, task_id: &TaskId, new_status: Status)
pub fn update_task(&self, task_id: &TaskId, new_status: Status)
Examples found in repository?
examples/demo.rs (line 42)
5fn main() {
6 let state = SBState::new(SBStateConfig {
7 silent: false,
8 task_name_width: TaskNameWidth::ExactRatio(0.25),
9 ..Default::default()
10 });
11
12 // The handles for these tasks are immediately dropped, so we automatically remove them.
13 // Except for error/info, which we display for a little while before removing automatically.
14 {
15 {
16 let task_id = state.add_task("finished task", Status::Finished);
17 state.add_subtask(&task_id, Status::Started);
18 }
19 let _ = state.add_task("error task", Status::Error);
20 let _ = state.add_task("started task", Status::Started);
21 let _ = state.add_task("queued task", Status::Queued);
22 }
23
24 let mut tasks = (0..10)
25 .into_iter()
26 .map(|index| {
27 let state = state.clone();
28 std::thread::spawn(move || {
29 std::thread::sleep(Duration::from_secs(index));
30 let task_id = state.add_task(format!("Task {index}"), Status::Started);
31 std::thread::sleep(Duration::from_secs(index.min(3)));
32 let sub_tasks = (0..10)
33 .into_iter()
34 .map(|_| state.add_subtask(&task_id, Status::Started))
35 .collect::<Vec<_>>();
36
37 for sub_task_id in sub_tasks {
38 std::thread::sleep(Duration::from_secs((index + 1).min(3)));
39 state.update_subtask(&task_id, &sub_task_id, Status::Finished);
40 }
41
42 state.update_task(&task_id, Status::Finished);
43 })
44 })
45 .collect::<Vec<_>>();
46
47 tasks.push(std::thread::spawn({
48 let state = state.clone();
49 move || {
50 let task_id = state.add_task(format!("Task with no children"), Status::Started);
51 std::thread::sleep(Duration::from_secs(10));
52 state.update_task(&task_id, Status::Finished);
53 }
54 }));
55
56 tasks.push(std::thread::spawn(move || {
57 std::thread::sleep(Duration::from_secs(4));
58 state.info("Here's an informational message");
59 std::thread::sleep(Duration::from_secs(8));
60 state.info("Here's another one :)");
61 }));
62
63 for task in tasks {
64 task.join().unwrap();
65 }
66}Sourcepub fn add_subtask(&self, task_id: &TaskId, status: Status) -> TaskId
pub fn add_subtask(&self, task_id: &TaskId, status: Status) -> TaskId
Examples found in repository?
examples/demo.rs (line 17)
5fn main() {
6 let state = SBState::new(SBStateConfig {
7 silent: false,
8 task_name_width: TaskNameWidth::ExactRatio(0.25),
9 ..Default::default()
10 });
11
12 // The handles for these tasks are immediately dropped, so we automatically remove them.
13 // Except for error/info, which we display for a little while before removing automatically.
14 {
15 {
16 let task_id = state.add_task("finished task", Status::Finished);
17 state.add_subtask(&task_id, Status::Started);
18 }
19 let _ = state.add_task("error task", Status::Error);
20 let _ = state.add_task("started task", Status::Started);
21 let _ = state.add_task("queued task", Status::Queued);
22 }
23
24 let mut tasks = (0..10)
25 .into_iter()
26 .map(|index| {
27 let state = state.clone();
28 std::thread::spawn(move || {
29 std::thread::sleep(Duration::from_secs(index));
30 let task_id = state.add_task(format!("Task {index}"), Status::Started);
31 std::thread::sleep(Duration::from_secs(index.min(3)));
32 let sub_tasks = (0..10)
33 .into_iter()
34 .map(|_| state.add_subtask(&task_id, Status::Started))
35 .collect::<Vec<_>>();
36
37 for sub_task_id in sub_tasks {
38 std::thread::sleep(Duration::from_secs((index + 1).min(3)));
39 state.update_subtask(&task_id, &sub_task_id, Status::Finished);
40 }
41
42 state.update_task(&task_id, Status::Finished);
43 })
44 })
45 .collect::<Vec<_>>();
46
47 tasks.push(std::thread::spawn({
48 let state = state.clone();
49 move || {
50 let task_id = state.add_task(format!("Task with no children"), Status::Started);
51 std::thread::sleep(Duration::from_secs(10));
52 state.update_task(&task_id, Status::Finished);
53 }
54 }));
55
56 tasks.push(std::thread::spawn(move || {
57 std::thread::sleep(Duration::from_secs(4));
58 state.info("Here's an informational message");
59 std::thread::sleep(Duration::from_secs(8));
60 state.info("Here's another one :)");
61 }));
62
63 for task in tasks {
64 task.join().unwrap();
65 }
66}Sourcepub fn update_subtask(
&self,
task_id: &TaskId,
sub_task_id: &TaskId,
status: Status,
)
pub fn update_subtask( &self, task_id: &TaskId, sub_task_id: &TaskId, status: Status, )
Examples found in repository?
examples/demo.rs (line 39)
5fn main() {
6 let state = SBState::new(SBStateConfig {
7 silent: false,
8 task_name_width: TaskNameWidth::ExactRatio(0.25),
9 ..Default::default()
10 });
11
12 // The handles for these tasks are immediately dropped, so we automatically remove them.
13 // Except for error/info, which we display for a little while before removing automatically.
14 {
15 {
16 let task_id = state.add_task("finished task", Status::Finished);
17 state.add_subtask(&task_id, Status::Started);
18 }
19 let _ = state.add_task("error task", Status::Error);
20 let _ = state.add_task("started task", Status::Started);
21 let _ = state.add_task("queued task", Status::Queued);
22 }
23
24 let mut tasks = (0..10)
25 .into_iter()
26 .map(|index| {
27 let state = state.clone();
28 std::thread::spawn(move || {
29 std::thread::sleep(Duration::from_secs(index));
30 let task_id = state.add_task(format!("Task {index}"), Status::Started);
31 std::thread::sleep(Duration::from_secs(index.min(3)));
32 let sub_tasks = (0..10)
33 .into_iter()
34 .map(|_| state.add_subtask(&task_id, Status::Started))
35 .collect::<Vec<_>>();
36
37 for sub_task_id in sub_tasks {
38 std::thread::sleep(Duration::from_secs((index + 1).min(3)));
39 state.update_subtask(&task_id, &sub_task_id, Status::Finished);
40 }
41
42 state.update_task(&task_id, Status::Finished);
43 })
44 })
45 .collect::<Vec<_>>();
46
47 tasks.push(std::thread::spawn({
48 let state = state.clone();
49 move || {
50 let task_id = state.add_task(format!("Task with no children"), Status::Started);
51 std::thread::sleep(Duration::from_secs(10));
52 state.update_task(&task_id, Status::Finished);
53 }
54 }));
55
56 tasks.push(std::thread::spawn(move || {
57 std::thread::sleep(Duration::from_secs(4));
58 state.info("Here's an informational message");
59 std::thread::sleep(Duration::from_secs(8));
60 state.info("Here's another one :)");
61 }));
62
63 for task in tasks {
64 task.join().unwrap();
65 }
66}Trait Implementations§
Auto Trait Implementations§
impl Freeze for SBState
impl RefUnwindSafe for SBState
impl Send for SBState
impl Sync for SBState
impl Unpin for SBState
impl UnwindSafe for SBState
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