add documentation

This commit is contained in:
zekro committed 2026-07-26 23:52:26 +02:00
1 parent c367d3f3ca
commit 45fbc088ba
5 files changed
+101

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
# The Problem
We have a `CredentialManager` implementation which can be in two states: **locked** or **unlocked**.
When the manager is locked, it can be unlocked with the `unlock(...)` method. Now unlocked, the `set(...)` and `get(...)` methods can be performed on the manager. Also, it can be locked again using the `lock()` method.
```rust
let mut pw = CredentialManager::new();
pw.unlock("pssst");
pw.set("foo", "bar");
let val = pw.get("foo");
pw.lock();
```
But with the current implementation, on a locked manager, the `get` and `set` could be performed which would result in erroneous results.
```rust
let mut pw = CredentialManager::new();
pw.set("foo", "bar"); // -> 💥
```
Also, nothing prevents us from unlocking an already unlocked manager as well as locking an already locked manager.
```rust
let mut pw = CredentialManager::new();
pw.unlock("pssst");
pw.unlock("pssst"); // -> 💥
let mut pw = CredentialManager::new();
pw.lock(); // -> 💥
```