Rust learning: lessons, notes, and exercise crates
This commit is contained in:
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
sync::atomic::{AtomicU32, Ordering},
|
||||
};
|
||||
|
||||
use tasks::store::Store;
|
||||
use tasks::task::Priority;
|
||||
|
||||
pub fn temp_path() -> PathBuf {
|
||||
static N: AtomicU32 = AtomicU32::new(0);
|
||||
let n = N.fetch_add(1, Ordering::Relaxed);
|
||||
std::env::temp_dir().join(format!("tasks-{}-{}.txt", std::process::id(), n))
|
||||
}
|
||||
|
||||
pub fn args(list: &[&str]) -> Vec<String> {
|
||||
list.iter().map(|s| s.to_string()).collect()
|
||||
}
|
||||
|
||||
/// One task per priority, ids 1..=3, task 1 already completed.
|
||||
pub fn three_tasks() -> Store {
|
||||
let mut store = Store::new();
|
||||
store.add("low task", Priority::Low);
|
||||
store.add("medium task", Priority::Medium);
|
||||
store.add("high task", Priority::High);
|
||||
store.complete(1).expect("task 1 was just added");
|
||||
store
|
||||
}
|
||||
Reference in New Issue
Block a user