Files
SwEdryG 72543ebb36 Добавить main.rs
тут к слову ничего нет интересного
2026-06-10 23:58:29 +03:00

109 lines
3.3 KiB
Rust

use std::{io::Write};
enum ClearanceLevel{ A, B, C, D }
enum InputType {
Text(String),
Number(u8),
}
impl InputType{
fn unwrap_txt(self) -> String{
match self {
InputType::Text(s) => s,
_ => panic!("Ожидался текст!"),
}
}
fn unwrap_num(self) -> u8{
match self {
InputType::Number(n) => n,
_ => panic!("Ожидалось число!"),
}
}
}
fn read_any(mode: bool) -> InputType {
std::io::stdout().flush().expect("Не удалось вывести строку");
let mut input = String::new();
std::io::stdin().read_line(&mut input).expect("Не удалось считать значение");
let input = input.trim();
if mode{
InputType::Text(input.to_string())
}else{
let input = input.parse::<u8>().expect("Введено не число");
InputType::Number(input)
}
}
struct User{
name: String,
age: u8,
pass: String,
cl: ClearanceLevel,
email: String,
}
fn print_cl(cl: &ClearanceLevel){
match cl {
ClearanceLevel::A => println!("Высокий"),
ClearanceLevel::B => println!("Средний"),
ClearanceLevel::C => println!("Низкий"),
ClearanceLevel::D => println!("Самый низкий"),
}
}
fn user_print(v: &User){
println!("Сотрудник: {}", v.name);
println!("Возраст: {}", v.age);
print!("Пароль: {}", "*".repeat(v.pass.chars().count()));
println!("");
print!("Уровень допуска: ");
print_cl(&v.cl);
println!("Email: {}",v.email);
}
fn main() {
print!("Введите кол-во сотрудников: ");
let n = read_any(false).unwrap_num();
let mut employee: Vec<User> = vec![];
for x in 1..=n {
println!("СОТРУДНИК №{}",x);
print!("Введите имя сотрудника: ");
let name_em = read_any(true).unwrap_txt();
print!("Введите возраст сотруника: ");
let age_em = read_any(false).unwrap_num();
print!("Введите пароль сотрудника: ");
let pass_em = read_any(true).unwrap_txt();
print!("Введите уровень доступа: 1-A, 2-B, 3-C, 4-D: ");
let choise = read_any(false).unwrap_num();
let cl_em = match choise{
1 => ClearanceLevel::A,
2 => ClearanceLevel::B,
3 => ClearanceLevel::C,
4 => ClearanceLevel::D,
_ => ClearanceLevel::C
};
print!("Введите почту сотруника: ");
let email_em = read_any(true).unwrap_txt();
let v = User{
name: name_em,
age: age_em,
pass: pass_em,
cl: cl_em,
email: email_em
};
employee.push(v);
}
println!("Введите номер пользователя для вывода данных. Всего пользователей: {}", employee.len());
let n = read_any(false).unwrap_num() as usize;
user_print(&employee[n-1]);
}