(path: &Path)
| 285 | } |
| 286 | |
| 287 | pub fn load(path: &Path) -> std::io::Result<Self> { |
| 288 | let content = std::fs::read_to_string(path)?; |
| 289 | // v2: {"version":2, "sessions":[...], "categories":[...]}. v1: a bare |
| 290 | // array of {session_id, category}. Probe for the versioned object first, |
| 291 | // then fall back to the legacy array so old files load losslessly. |
| 292 | if let Ok(persisted) = serde_json::from_str::<PersistedHints>(&content) { |
| 293 | return Ok(Self::from_persisted(persisted)); |
| 294 | } |
| 295 | let entries: Vec<PersistedHintEntry> = serde_json::from_str(&content).unwrap_or_default(); |
| 296 | Ok(Self::from_v1_entries(entries)) |
| 297 | } |
| 298 | |
| 299 | fn from_v1_entries(entries: Vec<PersistedHintEntry>) -> Self { |
| 300 | // A v1 entry records that the category was hinted once; it carries no |
no outgoing calls