gpt4 book ai didi

module - 如何将来自主模块的类型包含在同一个 crate 的其他文件中?

转载 作者:行者123 更新时间:2023-11-29 08:29:12 24 4
gpt4 key购买 nike

我正在编写一个名为 my_new_lib 的 Rust 库,并具有以下文件结构:

├── my_new_lib
├── src
├── lib.rs
└── file1.rs
├── tests

lib.rs中我定义了一个结构:

/// content of lib.rs

pub struct my_struct {}

file1.rs中我想使用my_struct,例如:

/// content of file1.rs

use ????

pub struct my_second_struct {
member1: my_struct
}

我应该在 file1.rsuse 子句中放入什么才能使其工作?

最佳答案

您必须使用 crate 关键字来访问您的 crate 的根目录:

use crate::MyStruct;

关于module - 如何将来自主模块的类型包含在同一个 crate 的其他文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54287835/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com