No method named make_noise for type pet::Cat in current scope

In the Cat type, it shows that the method make_noise is implemented via a trait, however, the code errors because it can't find make_noise in the Cat type in the scope.

Is there any way to fix this issue while keeping the Pet trait?

src/pet.rs

trait Pet {
    fn make_noise(&self) -> ();
}

pub struct Cat {
    pub name: String,
    pub age: i64
}

impl Pet for Cat {
    fn make_noise(&self) -> () {
        println!("Meow!");
    }
}

src/main.rs

mod pet;
use pet::{Cat};

fn main() {
    let fluffy = Cat {
        name: String::from("Fluffy"),
        age: 5
    };

    fluffy.make_noise();
} 

The Pet trait isn't in scope...

use pet::Pet;
2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.