In src/lib.rs
I have the following
extern crate opal_core;
mod functions;
mod context;
mod shader;
Then in src/context.rs
I have something like this, which tries to import symbols from src/shader.rs
:
use opal_core::shader::Stage;
use opal_core::shader::Shader as ShaderTrait;
use opal_core::GraphicsContext as GraphicsContextTrait;
use functions::*; // this import works fine
use shader::*; // this one doesn't
pub struct GraphicsContext {
functions: Gl
}
fn shader_stage_to_int(stage: &Stage) -> u32 {
match stage {
&Stage::Vertex => VERTEX_SHADER,
&Stage::Geometry => GEOMETRY_SHADER,
&Stage::Fragment => FRAGMENT_SHADER,
}
}
impl GraphicsContextTrait for GraphicsContext {
/// Creates a shader object
fn create_shader(&self, stage: Stage, source: &str) -> Box<ShaderTrait> {
let id;
unsafe {
id = self.functions.CreateShader(shader_stage_to_int(&stage));
}
let shader = Shader {
id: id,
stage: stage,
context: self
};
Box::new(shader)
}
}
The problem is that the statement use shader::*;
gives the error unresolved import.
I was reading the docs and they said that use
statements always go from the root of the current crate (opal_driver_gl
) so I thought shader::*
should be importing opal_driver_gl::shader::*
but it doesn't appear to do so. Do I need to use the self
or super
keywords here?
Thanks if you can help.
Note that the behavior of
use
has changed from Rust 2015 to Rust 2018. See What are the valid path roots in the use keyword? for details.Rust 2018
To import a module on the same level, do the following:
random_file_0.rs
random_file_1.rs
or an alternative random_file_1.rs:
lib.rs
See Rust By Example for more information and examples. If that doesn't work, here is the code it shows:
Rust 2015
To import a module on the same level, do the following:
random_file_0.rs
:random_file_1.rs
:or an alternative
random_file_1.rs
:lib.rs
:Here is another example from a previous version of Rust By Example: