100 exercises to learn Rust
This commit is contained in:
28
exercises/05_ticket_v2/15_outro/src/lib.rs
Normal file
28
exercises/05_ticket_v2/15_outro/src/lib.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
// TODO: you have something to do in each of the modules in this crate!
|
||||
mod description;
|
||||
mod status;
|
||||
mod title;
|
||||
|
||||
// A common pattern in Rust is to split code into multiple (private) modules
|
||||
// and then re-export the public parts of those modules at the root of the crate.
|
||||
//
|
||||
// This hides the internal structure of the crate from your users, while still
|
||||
// allowing you to organize your code however you like.
|
||||
pub use description::TicketDescription;
|
||||
pub use status::Status;
|
||||
pub use title::TicketTitle;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
// We no longer need to make the fields private!
|
||||
// Since each field encapsulates its own validation logic, there is no risk of
|
||||
// a user of `Ticket` modifying the fields in a way that would break the
|
||||
// invariants of the struct.
|
||||
//
|
||||
// Careful though: if you had any invariants that spanned multiple fields, you
|
||||
// would need to ensure that those invariants are still maintained and go back
|
||||
// to making the fields private.
|
||||
pub struct Ticket {
|
||||
pub title: TicketTitle,
|
||||
pub description: TicketDescription,
|
||||
pub status: Status,
|
||||
}
|
||||
Reference in New Issue
Block a user