Mercurial > hg > Members > anatofuz > ie-virsh
comparison src/user.rs @ 41:63e77a9de3ab
...
author | AnaTofuZ <anatofuz@gmail.com> |
---|---|
date | Sun, 22 Nov 2020 16:48:05 +0900 |
parents | afec42bdd5ab |
children |
comparison
equal
deleted
inserted
replaced
40:d3055f6c6fb7 | 41:63e77a9de3ab |
---|---|
4 pub name: String, | 4 pub name: String, |
5 } | 5 } |
6 | 6 |
7 pub struct UserDetail<'a> { | 7 pub struct UserDetail<'a> { |
8 pub user: &'a User, | 8 pub user: &'a User, |
9 pub grade: String, | 9 pub year: String, |
10 pub affilication: String, | |
10 } | 11 } |
11 | 12 |
12 impl<'a> UserDetail<'a> { | 13 impl<'a> UserDetail<'a> { |
13 pub fn new(user: &'a User) -> UserDetail { | 14 pub fn new(user: &'a User) -> UserDetail { |
14 // e195730 -> 19 | 15 // e195730 -> 19 |
15 let year = user.name.chars().skip(1).take(2).collect::<String>(); | 16 let year = user.name.chars().skip(1).take(2).collect::<String>(); |
16 // e195730 -> e19, tnal -> teacher | 17 // e195730 -> e19, tnal -> teacher |
17 let grade = if year.parse::<u8>().is_ok() { | 18 let affilication = if year.parse::<u8>().is_ok() { |
18 user.name.chars().take(3).collect::<String>() | 19 user.name.chars().take(3).collect::<String>() |
19 } else { | 20 } else { |
20 "teacher".to_string() | 21 "teacher".to_string() |
21 }; | 22 }; |
22 UserDetail { user, grade } | 23 UserDetail { |
24 user, | |
25 year, | |
26 affilication, | |
27 } | |
23 } | 28 } |
24 | 29 |
25 pub fn getpass(self) -> String { | 30 pub fn getpass(self) -> String { |
26 format!("{}/{}", self.grade, &self.user.name) | 31 format!("{}/{}", self.affilication, &self.user.name) |
27 } | 32 } |
28 } | 33 } |
29 | 34 |
30 pub fn getlogin(uid: u32) -> String { | 35 pub fn getlogin(uid: u32) -> String { |
31 use std::ffi::CStr; | 36 use std::ffi::CStr; |