¿Cómo dividir correctamente un módulo Rust en varios archivos?
¡Hola a todos! Empecé a estudiar Rust y me encontré con el problema de organizar el código en módulos. Tengo un archivo `main.rs` donde declaré el módulo `shapes` así:
```rust
mod shapes;
fn main() {
let rect = shapes::Rectangle::new(3.0, 4.0);
println!("Área: {}", rect.area());
}
```
En `shapes.rs` definí las estructuras y funciones:
```rust
pub struct Rectangle {
width: f64,
height: f64,
}
impl Rectangle {
pub fn new(w: f64, h: f64) -> Rectangle {
Rectangle { width: w, height: h }
}
pub fn area(&self) -> f64 {
self.width * self.height
}
}
```
Todo funciona, pero ahora quiero agregar más figuras: `Circle`, `Triangle`. Si meto todo en un solo `shapes.rs`, el archivo se volverá enorme. Intenté crear una carpeta `shapes/` y poner allí `mod.rs`, `rectangle.rs`, `circle.rs`. En `mod.rs` escribí:
```rust
pub mod rectangle;
pub mod circle;
```
Pero el compilador da errores de que no puede encontrar los tipos. ¿Cómo se hace correctamente?