mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Michele Sessa
c6a2e5d80a
|
2 years ago | |
---|---|---|
.. | ||
README.md | 2 years ago |
README.md
office_worker
Instructions
Create a structure OfficeWorker
having the following public fields:
name
asString
.age
asu32
.role
asWorkerRole
.
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.
Invalid inputs won't be tested.
Expected Functions and Data Structures
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.
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:
$ cargo run
New worker: OfficeWorker { name: "Manuel", age: 23, role: Admin }
New worker: OfficeWorker { name: "Jean Jacques", age: 44, role: Guest }
$