Import sibling module

Hi guys, I’m trying to import a sibling module while keeping the namespace and failing hard. My directory structure is:

/src
├── lib.rs
├── math.rs
└── terrain.rs

I’m trying to grab the functions from math.rs so I can do something like math::lerp() instead of importing all the functions into the namespace (like lerp()).

I already added mod math in lib.rs. I’ve tried using use super::math, use math; and use crate::math, etc. but I always get some error about type ascription or using an undefined module. I’m on Rust 1.35.

I think I’ve been at this for about an hour now, can it be done?

If you are trying to call it inside lib.rs you don’t need to do anything besides declaring mod math.rs.

If it’s inside terrain.rs make sure you declared both modules inside lib.rs and you can use super::math or use crate::math in terrain.rs.

3 Likes

Sorry, I forgot to mention it was inside terrain. I did a hard reset in git and used use super::math and now it works. Maybe I was doing something else wrong :thinking: Thanks for the help!