Add session persistence helpers for save/load state#111
Closed
ryanoneill wants to merge 3 commits intofeature/structured-errorsfrom
Closed
Add session persistence helpers for save/load state#111ryanoneill wants to merge 3 commits intofeature/structured-errorsfrom
ryanoneill wants to merge 3 commits intofeature/structured-errorsfrom
Conversation
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>
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
load_state<S: DeserializeOwned>(path)function that reads JSON and deserializes into any compatible typeCommand::save_state<S: Serialize>(state, path)that serializes to JSON and writes to disk#[cfg(feature = "serialization")]EnvisionError::Config { field, reason }variant from Replace string-based error variants with structured fields #107 for deserialization errorsenvision::app::persistenceandenvision::app::load_stateDepends on #107 (structured error variants).
Test plan
cargo test— all tests pass (6 new persistence tests)cargo clippy -- -D warnings— cleancargo check --no-default-features— compiles (persistence excluded)cargo test --doc— 274 doc tests pass (4 new)cargo build --examples— compiles🤖 Generated with Claude Code