-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Xila-Project/Feature/Users
A beginning
- Loading branch information
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use super::*; | ||
use std::{ | ||
collections::HashMap, | ||
sync::{Arc, RwLock}, | ||
}; | ||
|
||
struct Internal_user_type { | ||
pub Name: String, | ||
} | ||
|
||
pub struct Manager_type { | ||
Users: Arc<RwLock<HashMap<Identifier_type, Internal_user_type>>>, | ||
} | ||
|
||
impl Manager_type { | ||
pub fn New() -> Self { | ||
Self { | ||
Users: Arc::new(RwLock::new(HashMap::new())), | ||
} | ||
} | ||
|
||
pub fn Get_user_name(&self, Identifier: Identifier_type) -> Option<String> { | ||
let Users = self.Users.read().unwrap(); | ||
Some(Users.get(&Identifier).unwrap().Name.clone()) | ||
} | ||
|
||
pub fn Check_credentials(&self, User_name: &str, Password: &str) -> bool { | ||
true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use super::*; | ||
|
||
pub struct User_type<'a> { | ||
User_manager: &'a Manager_type, | ||
Identifier: Identifier_type, | ||
} | ||
|
||
impl<'a> User_type<'a> { | ||
pub fn New(User_manager: &'a Manager_type, Identifier: Identifier_type) -> Self { | ||
User_type { | ||
User_manager, | ||
Identifier, | ||
} | ||
} | ||
|
||
pub fn Get_name(&self) -> String { | ||
self.User_manager.Get_user_name(self.Identifier).unwrap() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
type Identifier_type = u8; | ||
|
||
mod Manager; | ||
pub use Manager::*; | ||
|
||
mod User; | ||
pub use User::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters