Look up a previously-registered value by walking up the process tree from this process. Returns `None` if no ancestor has registered a value.
(kind: SessionKind)
| 84 | /// Look up a previously-registered value by walking up the process tree from |
| 85 | /// this process. Returns `None` if no ancestor has registered a value. |
| 86 | pub(crate) fn load<T: DeserializeOwned>(kind: SessionKind) -> Result<Option<T>> { |
| 87 | let dir = get_root_dir(kind); |
| 88 | let mut current_pid = std::process::id() as pid_t; |
| 89 | |
| 90 | while let Some(parent_pid) = get_parent_pid(current_pid) { |
| 91 | let path = get_state_file_path(&dir, parent_pid); |
| 92 | if path.exists() { |
| 93 | let raw = std::fs::read_to_string(path)?; |
| 94 | let value: T = serde_json::from_str(&raw)?; |
| 95 | return Ok(Some(value)); |
| 96 | } |
| 97 | current_pid = parent_pid; |
| 98 | } |
| 99 | |
| 100 | Ok(None) |
| 101 | } |
no test coverage detected