Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Service {
- is_admin: bool,
- is_authed: bool,
- is_logged_out: bool,
- }
- impl Service {
- fn authenticate<S>(&mut self, passwd: S) -> Result<(), String>
- where S: AsRef<str>
- {
- if passwd.as_ref() == "secretpassword" {
- self.is_authed = true;
- Ok(())
- } else {
- Err("Bad password".into())
- }
- }
- fn escalate<S>(&mut self, passwd: S) -> Result<(), String>
- where S: AsRef<str>
- {
- if passwd.as_ref() == "adminpasswd" {
- self.is_admin = true;
- Ok(())
- } else {
- Err("Bad password".into())
- }
- }
- fn perform_action(&self) {
- assert!(self.is_authed)
- println!("we are authed")
- }
- fn perform_admin_action(&self) {
- assert!(self.is_admin)
- println!("we are admin")
- }
- }
Add Comment
Please, Sign In to add comment