diff --git a/01-problem/src/main.rs b/01-problem/src/main.rs index d8930c9..22c551a 100644 --- a/01-problem/src/main.rs +++ b/01-problem/src/main.rs @@ -13,7 +13,7 @@ impl CredentialManager { } } - pub fn unlock(&self, master_secret: &str) { + pub fn unlock(&mut self, master_secret: &str) { todo!() } @@ -21,11 +21,11 @@ impl CredentialManager { todo!() } - pub fn get(&mut self, key: &str) -> Option<&str> { + pub fn get(&self, key: &str) -> Option<&str> { todo!() } - pub fn lock(&self) { + pub fn lock(&mut self) { todo!() } } diff --git a/02-runtime-check/src/main.rs b/02-runtime-check/src/main.rs index bf9cd4b..70bfc3d 100644 --- a/02-runtime-check/src/main.rs +++ b/02-runtime-check/src/main.rs @@ -15,10 +15,11 @@ impl CredentialManager { } } - pub fn unlock(&self, master_secret: &str) -> Result<(), &'static str> { + pub fn unlock(&mut self, master_secret: &str) -> Result<(), &'static str> { if !self.locked { return Err("already unlocked"); } + self.locked = false; todo!() } @@ -29,17 +30,18 @@ impl CredentialManager { todo!() } - pub fn get(&mut self, key: &str) -> Result, &'static str> { + pub fn get(&self, key: &str) -> Result, &'static str> { if self.locked { return Err("locked"); } todo!() } - pub fn lock(&self) -> Result<(), &'static str> { + pub fn lock(&mut self) -> Result<(), &'static str> { if self.locked { return Err("already locked"); } + self.locked = true; todo!() } } diff --git a/03-builder-pattern/src/main.rs b/03-builder-pattern/src/main.rs index 52b4f6f..e6269d9 100644 --- a/03-builder-pattern/src/main.rs +++ b/03-builder-pattern/src/main.rs @@ -29,7 +29,7 @@ impl UnlockedCredentialManager { todo!() } - pub fn get(&mut self, key: &str) -> Option<&str> { + pub fn get(&self, key: &str) -> Option<&str> { todo!() } diff --git a/04-typestate/src/main.rs b/04-typestate/src/main.rs index dd25450..fd6cec9 100644 --- a/04-typestate/src/main.rs +++ b/04-typestate/src/main.rs @@ -33,7 +33,7 @@ impl CredentialManager { todo!() } - pub fn get(&mut self, key: &str) -> Option<&str> { + pub fn get(&self, key: &str) -> Option<&str> { todo!() }