'use' 关键字无效(从同级文件调用)

'use' keyword not working (calling from sibling file)

我正在尝试 use 来自 chunk.rsvalue.rs 文件中的结构,但它不起作用。这是我当前的文件层次结构。

src
|
|---value.rs
|---chunk.rs
|---other files

这是我的 value.rs 代码:

pub enum Value {
}

pub struct ValueArray {
    values: Vec<Value>,
}

pub impl Value {
    pub fn new() -> Value {
        Value {
            values: Vec::new(),
        }
    }

    pub fn write_chunk(&mut self, value: Value) {
        self.code.push(value);
    }
}

这是我的 chunk.rs 代码:

use crate::value::ValueArray; // Error Here

pub enum OpCode {
    OpReturn,
}

pub struct Chunk {
    pub code: Vec<OpCode>,
    constants: value::ValueArray,
}

impl Chunk {
    pub fn new() -> Chunk {
        Chunk {
            code: Vec::new(),
            constants: value::ValueArray::new(),
        }
    }

    pub fn write_chunk(&mut self, byte: OpCode) {
        self.code.push(byte);
    }
}

这是我的确切错误消息:

unresolved import `crate::value`
could not find `value` in the crate rootrustc(E0432)
chunk.rs(1, 12): could not find `value` in the crate root

我不确定为什么它不起作用,因为我在另一个同级文件中做了非常相似的事情。我是 Rust 的新手,所以非常感谢您的所有帮助。谢谢

我用来包含带有裸 structs/functions(未定义显式模块)的文件(“lib.rs”)的语法是:

mod lib;
use crate::lib::*;

所以你肯定漏了mod value;.

您需要在 lib.rs 文件中定义 value 模块

pub mod value;