Browse Source

docs(get_document_id): update subject

- remove id from Office<Num> structures
- update main function to be consistent
DEV-4017-prototypes-exercise-1-animals
nprimo 2 years ago committed by Niccolò Primo
parent
commit
6becf34972
  1. 25
      subjects/get_document_id/README.md

25
subjects/get_document_id/README.md

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

Loading…
Cancel
Save