add documentation
This commit is contained in:
1 parent
c367d3f3ca
commit
45fbc088ba
5 files changed
+101
No files matched your search
@@ -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.
|
||||
Reference in new issue
Block a user