From ccc0a2dc0a21bba023db0418436edbe721ab3058 Mon Sep 17 00:00:00 2001 From: mikysett Date: Mon, 14 Nov 2022 14:48:23 +0000 Subject: [PATCH] feat(office_worker): add new exercise for rust exams --- subjects/office_worker/README.md | 56 ++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 subjects/office_worker/README.md diff --git a/subjects/office_worker/README.md b/subjects/office_worker/README.md new file mode 100644 index 00000000..2768f001 --- /dev/null +++ b/subjects/office_worker/README.md @@ -0,0 +1,56 @@ +## office_worker + +### Instructions + +Create a structure `OfficeWorker` having the following public fields: +- `name` as `String`. +- `age` as `u32`. +- `role` as `WorkerRole`. + +Create an enum `WorkerRole` which can be `Admin`, `User` or `Guest`. + +Implement for both the trait `From<&str>`. For `OfficeWorker` the string will have the format `"name,age,role"`, for `WorkerRole` the format of the string will be the `"role"` name in lower case. + +### Expected Functions and Data Structures + +```rust +use crate::OfficeWorker::*; + +#[derive(Debug, PartialEq, Eq)] +pub struct OfficeWorker { +} + +#[derive(Debug, PartialEq, Eq)] +pub enum WorkerRole { +} + +impl From<&str> for OfficeWorker { +} + +impl From<&str> for WorkerRole { +} +``` + +### Usage + +Here is a program to test your function. + +```rust +use office_worker::*; + +fn main() { + println!("New worker: {:?}", + OfficeWorker::from("Manuel,23,admin")); + println!("New worker: {:?}", + OfficeWorker::from("Jean Jacques,44,guest")); +} +``` + +And its output: + +```console +$ cargo run +New worker: OfficeWorker { name: "Manuel", age: 23, role: Admin } +New worker: OfficeWorker { name: "Jean Jacques", age: 44, role: Guest } +$ +```