init
This commit is contained in:
commit
0dc3a6c0f6
11 files changed
+243
No files matched your search
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "builder-pattern"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
@@ -0,0 +1,49 @@
|
||||
#![allow(unused)]
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
struct LockedCredentialManager {
|
||||
entries: HashMap<String, String>,
|
||||
}
|
||||
|
||||
struct UnlockedCredentialManager {
|
||||
entries: HashMap<String, String>,
|
||||
}
|
||||
|
||||
impl LockedCredentialManager {
|
||||
pub fn new() -> LockedCredentialManager {
|
||||
LockedCredentialManager {
|
||||
entries: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unlock(self, master_secret: &str) -> UnlockedCredentialManager {
|
||||
UnlockedCredentialManager {
|
||||
entries: self.entries,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl UnlockedCredentialManager {
|
||||
pub fn set(&mut self, key: &str, secret: &str) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn get(&mut self, key: &str) -> Option<&str> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn lock(self) -> LockedCredentialManager {
|
||||
LockedCredentialManager {
|
||||
entries: self.entries,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let pw = LockedCredentialManager::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