Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/modules/solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,26 @@ fn main() {
window.draw();
}
```

The solution demonstrates the standard Rust module hierarchy and visibility
rules:

- **Module Hierarchy:** Sub-modules are placed in a directory (`src/widgets/`)
and declared in a corresponding file (`src/widgets.rs`).
- **Encapsulation:** Visibility is controlled with `pub`. Fields remain private
by default, while types and the `Widget` trait are exposed for external use.
- **Re-exports:** Using `pub use` in `src/widgets.rs` provides a flat public
API, allowing users to import `widgets::Button` instead of the internal
`widgets::button::Button`.
- **Path Resolution:** Sub-modules use `super::Widget` to refer to items in the
parent module.

<details>

- **Module Styles:** This structure uses the modern (Rust 2018+) module style.
Previously, `src/widgets/mod.rs` was required instead of `src/widgets.rs`.
- **API Design:** Re-exporting is a powerful tool for decoupling your internal
code organization from your library's public interface, allowing for
refactoring without breaking changes.

</details>