add documentation

This commit is contained in:
zekro committed 2026-07-27 09:22:30 +02:00
1 parent 88661ec960
commit dcef2470cb
5 files changed
+101

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
# Solution 1: Runtime Checks
One solution to the problem would be to simply check the locked state and restrict methods to be only callable in the corrent locked state.
```rust
let mut pw = CredentialManager::new();
pw.set("foo", "bar")?; // this would bail with an error result
pw.unlock("pssst")?;
pw.unlock("pssst")?; // this would bail with an error result
pw.set("foo", "bar")?;
let val = pw.get("foo")?;
pw.lock()?;
pw.lock()?; // this would bail with an error result
```
## Caveats
Performing runtime checks on the state requires returning `Result` and also requires the check and handling of erroneous results on every call to the manager.