init
This commit is contained in:
commit
0dc3a6c0f6
11 files changed
+243
No files matched your search
@@ -0,0 +1,54 @@
|
||||
#![allow(unused)]
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
struct Locked;
|
||||
struct Unlocked;
|
||||
|
||||
struct CredentialManager<State = Locked> {
|
||||
entries: HashMap<String, String>,
|
||||
state: std::marker::PhantomData<State>,
|
||||
}
|
||||
|
||||
impl CredentialManager {
|
||||
pub fn new() -> CredentialManager<Locked> {
|
||||
CredentialManager {
|
||||
entries: HashMap::new(),
|
||||
state: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CredentialManager<Locked> {
|
||||
pub fn unlock(self, master_secret: &str) -> CredentialManager<Unlocked> {
|
||||
CredentialManager {
|
||||
entries: self.entries,
|
||||
state: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CredentialManager<Unlocked> {
|
||||
pub fn set(&mut self, key: &str, secret: &str) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn get(&mut self, key: &str) -> Option<&str> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn lock(self) -> CredentialManager<Locked> {
|
||||
CredentialManager {
|
||||
entries: self.entries,
|
||||
state: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let pw = CredentialManager::new();
|
||||
let mut pw = pw.unlock("pssst");
|
||||
pw.set("foo", "bar");
|
||||
let val = pw.get("foo");
|
||||
pw.lock();
|
||||
}
|
||||
Reference in new issue
Block a user