In my main.rs I get code completion just fine. But I don't get it in my module files.
My folder structure looks like this:
src/
|___game_components/
| |___card.rs
|___game_components.rs
|___main.rs
The program builds and runs just fine (aside from some unused warnings). And when editing my main.rs file I get code completion for str
, rand
and my Card
struct. However when editing my either card.rs I don't get any code completion at all, not even for the Card struct that is defined in that file.
I have tried reinstalling rust-analyzer and I have ran rustup update
, but no luck.
Am I missing something, or is there a bug somewhere?
Edit: added file contents
main.rs:
pub mod game_components;
use game_components::card::Card;
fn main() {
println!("{:?}", Card::new(5));
}
game_components.rs:
pub mod card;
card.rs:
const FACES: [&str; 13] = [
"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace",
];
const SUITS: [&str; 4] = ["Hearts", "Clubs", "Diamonds", "Spades"];
#[derive(Debug)]
pub struct Card {
value: u8,
face: u8,
suit: u8,
}
impl Card {
pub fn new(value: u8) -> Card {
if value >= 52 {
panic!("Value cannot be larger than 51, got {}", value)
}
Card {
value,
face: value % 13,
suit: value / 13,
}
}
pub fn get_name(&self) -> String {
format!(
"{} of {}",
FACES[self.face as usize], SUITS[self.suit as usize]
)
}
}