Skip to main content

proc_tree/
traits.rs

1//! Traits for process tree storage backends.
2//!
3//! Implement `TreeStore` and `CacheStore` to provide your own storage
4//! (e.g., moka cache, Redis, dashmap) while reusing the process tree
5//! algorithms in [`crate::ops`].
6
7use crate::types::{PidNode, ProcInfo};
8
9/// Trait for process tree storage.
10///
11/// Implement this trait to provide your own storage backend.
12pub trait TreeStore {
13    /// Get a tree node by PID.
14    fn get_node(&self, pid: u32) -> Option<PidNode>;
15
16    /// Insert or update a tree node.
17    fn insert_node(&self, pid: u32, node: PidNode);
18
19    /// Get all PIDs in the tree.
20    fn all_pids(&self) -> Vec<u32>;
21}
22
23/// Trait for process info cache.
24///
25/// Implement this trait to provide your own cache backend.
26pub trait CacheStore {
27    /// Get cached process info by PID.
28    fn get_info(&self, pid: u32) -> Option<ProcInfo>;
29
30    /// Insert or update process info.
31    fn insert_info(&self, pid: u32, info: ProcInfo);
32}