Trying to compile the following Rust code
mod traits { pub trait Dog { fn bark(&self) { println!("Bow"); } } } struct Dog; impl traits::Dog for Dog {} fn main() { let dog = Dog; dog.bark(); }
gives an error message
error[E0599]: no method named 'bark' found for type 'Dog' in the current scope --> src/main.rs:15:9 | 9 | struct Dog; | ----------- method 'bark' not found for this ... 15 | dog.bark(); | ^^^^ | = help: items from traits can only be used if the trait is in scope help: the following trait is implemented but not in scope, perhaps add a 'use' for it: | 1 | use crate::traits::Dog; |
If I add use crate::traits::Dog; , an error will appear:
error[E0255]: the name 'Dog' is defined multiple times --> src/main.rs:11:1 | 1 | use crate::traits::Dog; | ------------------ previous import of the trait 'Dog' here ... 11 | struct Dog; | ^^^^^^^^^^^ 'Dog' redefined here | = note: 'Dog' must be defined only once in the type namespace of this module
If I rename trait Dog to trait DogTrait , everything will work. How can I use a dash from a submodule with the same name as the structure in my main module?
source share