commit 72543ebb36dce7d45e4a80fe3f493e7f0e3af3e2 Author: SwEdryG Date: Wed Jun 10 23:58:29 2026 +0300 Добавить main.rs тут к слову ничего нет интересного diff --git a/main.rs b/main.rs new file mode 100644 index 0000000..f00c38e --- /dev/null +++ b/main.rs @@ -0,0 +1,109 @@ +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::().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 = 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]); +} \ No newline at end of file