Skip to main content

xtask_todo_lib/
lib.rs

1//! todo - workspace library
2//!
3//! Todo domain: create, list, complete, delete items with in-memory or pluggable storage.
4//! Also includes the devshell REPL/VFS logic used by the `cargo-devshell` binary (for test coverage).
5
6pub mod devshell;
7mod error;
8mod id;
9mod list;
10mod model;
11mod priority;
12mod repeat;
13mod store;
14
15pub use error::TodoError;
16pub use id::TodoId;
17pub use list::TodoList;
18pub use model::{ListFilter, ListOptions, ListSort, Todo, TodoPatch};
19pub use priority::Priority;
20pub use repeat::RepeatRule;
21pub use store::{InMemoryStore, Store};
22
23#[cfg(test)]
24mod tests;
25
26/// Serialize tests that use `std::env::set_current_dir` (process-global).
27#[cfg(test)]
28pub(crate) mod test_support {
29    use std::sync::{Mutex, OnceLock, PoisonError};
30
31    pub fn cwd_mutex() -> std::sync::MutexGuard<'static, ()> {
32        static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
33        LOCK.get_or_init(|| Mutex::new(()))
34            .lock()
35            .unwrap_or_else(PoisonError::into_inner)
36    }
37
38    /// Serialize `DEVSHELL_WORKSPACE_ROOT` with [`crate::devshell::vm::export_devshell_workspace_root_env`]
39    /// and `session_store` tests (parallel `cargo test`).
40    pub fn devshell_workspace_env_mutex() -> std::sync::MutexGuard<'static, ()> {
41        static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
42        LOCK.get_or_init(|| Mutex::new(()))
43            .lock()
44            .unwrap_or_else(PoisonError::into_inner)
45    }
46
47    /// Serialize VM-related environment mutation in tests (`DEVSHELL_VM*`, `PATH`, etc.).
48    pub fn vm_env_mutex() -> std::sync::MutexGuard<'static, ()> {
49        static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
50        LOCK.get_or_init(|| Mutex::new(()))
51            .lock()
52            .unwrap_or_else(PoisonError::into_inner)
53    }
54}