0

I have a src/lib.rs that contains:

pub trait Compile {
    fn from_source(src: &src) {
        parser::parse(src);
    }
}

And a src/compiler/interpreter.rs

use crate::Compile; // ERROR HERE - No Compile in the root

pub struct Interpreter;

impl Compile for Interpreter {}

I also have a src/compiler.rs

pub mod interpreter;

I want to be able to use the Compile trait within my interpreter impl however I cannot seem to figure out how import the trait. Any thoughts?

Its possible to do this in src/main.rs by doing:

mod lib;
use lib::Compile;
AJ D
  • 52
  • 1
  • 6

1 Answers1

1

The way I solved this issue was in src/main.rs I used:

use {ROOT CRATE PACKAGE NAME}::Compile;

This must bring Compile into the crate scope so now I can just do: use crate::Compile inside my compiler sub module.

AJ D
  • 52
  • 1
  • 6