docs(get_document_id): update subject

- remove id from Office<Num> structures
- update main function to be consistent
This commit is contained in:
nprimo 2022-11-21 15:46:52 +00:00 committed by Niccolò Primo
parent 6e10678bbc
commit 6becf34972
1 changed files with 4 additions and 21 deletions

View File

@ -30,19 +30,16 @@ pub enum ErrorOffice {
#[derive(PartialEq, Eq, Clone, Copy)]
pub struct OfficeOne {
pub next_office: Result<OfficeTwo, ErrorOffice>,
pub id: u32,
}
#[derive(PartialEq, Eq, Clone, Copy)]
pub struct OfficeTwo {
pub next_office: Result<OfficeThree, ErrorOffice>,
pub id: u32,
}
#[derive(PartialEq, Eq, Clone, Copy)]
pub struct OfficeThree {
pub next_office: Result<OfficeFour, ErrorOffice>,
pub id: u32,
}
#[derive(PartialEq, Eq, Clone, Copy)]
@ -68,39 +65,25 @@ fn main() {
next_office: Ok(OfficeThree {
next_office: Ok(OfficeFour {
document_id: Ok(13),
id: 4,
}),
id: 3,
}),
id: 2,
}),
id: 1,
};
let office_closed = {
OfficeOne {
next_office: Ok(OfficeTwo {
next_office: Err(ErrorOffice::OfficeClose(2)),
id: 2,
next_office: Err(ErrorOffice::OfficeClose(23)),
}),
id: 1,
}
};
match office_ok.get_document_id() {
Ok(id) => println!("Found a document with id {}", id),
Err(err) => match err {
ErrorOffice::OfficeClose(id) => println!("Error: office {id} closed!"),
ErrorOffice::OfficeNotFound(id) => println!("Error: office {id} not found!"),
ErrorOffice::OfficeFull(id) => println!("Error: office {id} full!"),
},
Err(err) => println!("Error: {:?}", err),
};
match office_closed.get_document_id() {
Ok(id) => println!("Found a document with id {}", id),
Err(err) => match err {
ErrorOffice::OfficeClose(id) => println!("Error: office {id} closed!"),
ErrorOffice::OfficeotFound(id) => println!("Error: office {id} not found!"),
ErrorOffice::OfficeFull(id) => println!("Error: office {id} full!"),
},
Err(err) => println!("Error: {:?}", err),
};
}
```
@ -110,6 +93,6 @@ And its output:
```console
$ cargo run
Found a document with id 13
Error: office 2 closed!
Error: OfficeClose(23)
$
```