-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved struct logic into its own module
- Loading branch information
1 parent
93a52a4
commit 31e44ff
Showing
2 changed files
with
46 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use serde::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
struct Definition { | ||
#[serde(rename(deserialize = "partOfSpeech"))] | ||
part_of_speech: String, | ||
text: String, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct ExampleUsage { | ||
text: String, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub(crate) struct WordOfTheDay { | ||
definitions: Vec<Definition>, | ||
examples: Vec<ExampleUsage>, | ||
note: String, | ||
word: String, | ||
} | ||
|
||
impl WordOfTheDay { | ||
pub fn display(&self) { | ||
println!("Word of the Day:"); | ||
println!(" {}\n", self.word); | ||
|
||
println!("Definitions:"); | ||
for definition in self.definitions.iter() { | ||
println!(" Part of speech: {}", definition.part_of_speech); | ||
println!(" Definition:"); | ||
println!(" {}\n", definition.text); | ||
} | ||
|
||
println!("Examples:"); | ||
for example in self.examples.iter() { | ||
println!(" Example:"); | ||
println!(" {}\n", example.text); | ||
} | ||
|
||
println!("Note:"); | ||
println!(" {}", self.note); | ||
} | ||
} |