I'm working on this example from a book. It gives me the following error message:
|
6 | println!("{}", basket.apples());
| ^^^^^^ not found in this scope
Both Println!. . . and let basket. . . are inside the main function. I cant seem to figure out why "basket" is out of scope here.
Any help is always appreciated.
fn main ()
{
println!("double = {}", 5_i32.double());
println!("double = {}", 5_i64.double());
println!("{}", basket.apples());
let basket = Fruit
{
apples: 5,
bananas: 5,
};
}
trait Double
{
fn double(&self) -> Self;
}
impl Double for i32
{
fn double(&self) -> Self
{
self*2
}
}
impl Double for i64
{
fn double(&self) -> Self
{
self*2
}
}
struct Fruit <T>
{
apples: T,
bananas: T,
}
impl <T: Double> Double for Fruit <T>
{
fn double (&self) -> Self
{
Fruit
{
apples: self.apples.double(),
bananas: self.apples.double(),
}
}
}