Rust 以不同名称重新导出模块
我想编写一个跨平台的库,因此我编写了以下代码Rust 以不同名称重新导出模块,rust,Rust,我想编写一个跨平台的库,因此我编写了以下代码 pub mod common; #[cfg(target_os = "Linux")] pub mod process_linux; #[cfg(target_os = "Windows")] pub mod process_windows; 但是现在我想在名称process下重新导出这两个模块。 这容易做到吗?我想我将来可能需要阅读更多关于模块和名称空间的内容,我尝试了以下方法: pub mod proc
pub mod common;
#[cfg(target_os = "Linux")]
pub mod process_linux;
#[cfg(target_os = "Windows")]
pub mod process_windows;
但是现在我想在名称process下重新导出这两个模块。
这容易做到吗?我想我将来可能需要阅读更多关于模块和名称空间的内容,我尝试了以下方法:
pub mod process {
#[cfg(target_os = "Linux")]
pub use process_linux::*;
#[cfg(target_os = "Windows")]
pub use process_windows::*;
}
但它仍然没有像我想要的那样工作,也许有人知道答案
编辑:
例如,我希望能够在不同的机器上运行相同的代码,如,但目前导入不起作用,我必须使用process_linux:
// doesnt work
use tryolib::process::*;
// works
use tryolib::process_linux::*;
好的,现在我试着:
#[cfg(target_os=“Linux”)]
modprocess_-linux;
#[cfg(target_os=“Windows”)]
mod进程窗口;
#[cfg(target_os=“Linux”)]
pub使用process_linux作为进程;
#[cfg(target_os=“Windows”)]
pub使用进程窗口作为进程;
您只是输入了一个错误,操作系统必须使用小写字母(as)。以下代码起作用():
#[cfg(target_os=“linux”)]
pub mod process_linux{
pub类型T=();
}
#[cfg(target_os=“linux”)]
使用process_linux作为进程;
fn main(){
let:进程::T=();
}
很抱歉,最近的编辑仍然不清楚问题出在哪里。那不是编译吗?这也不完全是一个问题,因为我们自己无法复制这一点。您可能还想了解以下内容的完整语法:您可以使用somecrate::module作为另一个名称代码>