1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-20 06:21:09 +02:00

Better demonstrate imports in modules exercise (#2514)

The solution to the modules exercise changes how `Button`, `Window`, and
`Label` are referenced, adding a `widgets::` prefix to them. This seems
weird to me because the more idiomatic thing to do would be to import
those types at the top of the file. Unless I'm missing a reason why the
solutions is written the way it is, I think this is a good
simplification.
This commit is contained in:
Nicole L 2024-12-16 08:42:22 -08:00 committed by GitHub
parent 999490fae4
commit c33a9b2ca4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -177,13 +177,12 @@ impl Widget for Window {
// ---- src/main.rs ----
mod widgets;
use widgets::Widget;
use widgets::{Button, Label, Widget, Window};
fn main() {
let mut window = widgets::Window::new("Rust GUI Demo 1.23");
window
.add_widget(Box::new(widgets::Label::new("This is a small text GUI demo.")));
window.add_widget(Box::new(widgets::Button::new("Click me!")));
let mut window = Window::new("Rust GUI Demo 1.23");
window.add_widget(Box::new(Label::new("This is a small text GUI demo.")));
window.add_widget(Box::new(Button::new("Click me!")));
window.draw();
}
```