From 6e10678bbc43eb3ced5883359cc9c9169e14984d Mon Sep 17 00:00:00 2001 From: nprimo Date: Thu, 17 Nov 2022 17:07:22 +0000 Subject: [PATCH] docs(get_document_id): make main function consistent with instructions --- subjects/get_document_id/README.md | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/subjects/get_document_id/README.md b/subjects/get_document_id/README.md index 7e799e83b..6679d474e 100644 --- a/subjects/get_document_id/README.md +++ b/subjects/get_document_id/README.md @@ -11,7 +11,7 @@ Create the following structures which will help you get the `document_id` of the `ErrorOffice` is an `enum` with `OfficeClosed(u32)`, `OfficeNotFound(u32)` or `OfficeFull(u32)`. -The `usize` is the `id` of the office generating the error. +The `u32` is the `id` of the office generating the error. Beside the structures, you must create a **function** named `get_document_id`, and associate it to the `OfficeOne` structure. @@ -30,16 +30,19 @@ pub enum ErrorOffice { #[derive(PartialEq, Eq, Clone, Copy)] pub struct OfficeOne { pub next_office: Result, + pub id: u32, } #[derive(PartialEq, Eq, Clone, Copy)] pub struct OfficeTwo { pub next_office: Result, + pub id: u32, } #[derive(PartialEq, Eq, Clone, Copy)] pub struct OfficeThree { pub next_office: Result, + pub id: u32, } #[derive(PartialEq, Eq, Clone, Copy)] @@ -65,32 +68,38 @@ 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(13)), + next_office: Err(ErrorOffice::OfficeClose(2)), + id: 2, }), + id: 1, } }; match office_ok.get_document_id() { Ok(id) => println!("Found a document with id {}", id), Err(err) => match err { - ErrorOffice::OfficeClose(_) => println!("Error: office closed!"), - ErrorOffice::OfficeNotFound(_) => println!("Error: office not found!"), - ErrorOffice::OfficeFull(_) => println!("Error: office full!"), + 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() { Ok(id) => println!("Found a document with id {}", id), Err(err) => match err { - ErrorOffice::OfficeClose(_) => println!("Error: office closed!"), - ErrorOffice::OfficeNotFound(_) => println!("Error: office not found!"), - ErrorOffice::OfficeFull(_) => println!("Error: office full!"), + 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!"), }, }; } @@ -101,6 +110,6 @@ And its output: ```console $ cargo run Found a document with id 13 -Error: office closed! +Error: office 2 closed! $ ```