Skip to content

Add session persistence helpers for save/load state#111

Closed
ryanoneill wants to merge 3 commits intofeature/structured-errorsfrom
feature/session-persistence
Closed

Add session persistence helpers for save/load state#111
ryanoneill wants to merge 3 commits intofeature/structured-errorsfrom
feature/session-persistence

Conversation

@ryanoneill
Copy link
Owner

Summary

  • Add load_state<S: DeserializeOwned>(path) function that reads JSON and deserializes into any compatible type
  • Add Command::save_state<S: Serialize>(state, path) that serializes to JSON and writes to disk
  • Both behind #[cfg(feature = "serialization")]
  • Uses structured EnvisionError::Config { field, reason } variant from Replace string-based error variants with structured fields #107 for deserialization errors
  • Module re-exported at envision::app::persistence and envision::app::load_state

Depends on #107 (structured error variants).

Test plan

  • cargo test — all tests pass (6 new persistence tests)
  • cargo clippy -- -D warnings — clean
  • cargo check --no-default-features — compiles (persistence excluded)
  • cargo test --doc — 274 doc tests pass (4 new)
  • cargo build --examples — compiles

🤖 Generated with Claude Code

ryanoneill and others added 3 commits March 1, 2026 20:44
Add load_state<S>(path) function that reads a JSON file and
deserializes into any DeserializeOwned type. Add Command::save_state()
that serializes state to JSON and writes to disk. Both behind the
serialization feature flag. Uses structured EnvisionError::Config
variant for deserialization errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add tokio "fs" feature to enable tokio::fs::write for async file I/O
in Command::save_state. File write errors are reported to the runtime's
error channel via try_perform_async.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
load_state now uses tokio::fs::read_to_string for non-blocking file I/O,
consistent with save_state's use of tokio::fs::write. All persistence
tests updated to #[tokio::test]. Added tokio-test dev-dependency for
async doc test support.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ryanoneill ryanoneill deleted the branch feature/structured-errors March 2, 2026 04:57
@ryanoneill ryanoneill closed this Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant