Skip to main content

proc_tree/
traits.rs

1//! Traits for process tree storage backends.
2//!
3//! Implement `ProcessStore` 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::ProcessInfo;
8
9/// Trait for process tree storage.
10///
11/// Implement this trait to provide your own storage backend.
12pub trait ProcessStore {
13    /// Get process info by PID.
14    fn get_process(&self, pid: u32) -> Option<ProcessInfo>;
15
16    /// Insert or update process info.
17    fn insert_process(&self, pid: u32, info: ProcessInfo);
18
19    /// Remove a process by PID. Returns the removed process info.
20    fn remove_process(&self, pid: u32) -> Option<ProcessInfo>;
21
22    /// Get all PIDs in the tree.
23    fn all_pids(&self) -> Vec<u32>;
24
25    /// Get direct children of a PID.
26    fn children_of(&self, pid: u32) -> Vec<u32>;
27}