I have code where I want to use a library but it seems like we cannot import libraries within mod
?
mod A {
pub struct Circle {
x: f64,
y: f64,
radius: f64,
}
struct BigCircle {
x: f64,
y: f64,
radius: f64,
}
impl Circle {
pub fn new(x: f64, y: f64, radius: f64) -> Circle {
Circle {
x: x,
y: y,
radius: radius,
}
}
pub fn area(&self) -> f64 {
std::f64::consts::PI * (self.radius * self.radius)
}
pub fn grow(&self, increment: f64) -> Circle {
// BigCircle { x: self.x, y: self.y, radius: self.radius + increment }
Circle::new(self.x, self.y, self.radius + increment)
}
pub fn print(&self) {
println!("Im a Circle");
}
}
}
fn main() {
let c = A::Circle::new(0.0, 0.0, 2.0);
println!("{}", c.area());
}
When I use this code it throws an error I because of the usage of const
. if I don't put my code inside mod
, everything works fine
error: failed to resolve. Use of undeclared type or module `std::f64::consts` [--explain E0433]
--> src/main.rs:27:13
|>
27 |> std::f64::consts::PI * (self.radius * self.radius)
|> ^^^^^^^^^^^^^^^^^^^^