< 返回版块

abliger 发表于 2023-04-11 20:15

Tags:prelude_import

我想要实现预导入的功能,就想到了rust 中的 Ok,Err 等类型.查看源码他是这样实现预导出的

#![feature(prelude_import)]

#[prelude_import]
#[allow(unused)]
use prelude::v1::*;

但我这样实现后编译器报错,最终需要这样实现

//#![feature(prelude_import)]

//#[prelude_import]
#[feature(prelude_import)]
pub use prelude::*;

prelude文件

//pub use std::prelude::rust_2021::*;
//pub use core::prelude::rust_2021::*;

#[cfg(not(feature = "regex"))]
pub use crate::grammer::parse;
#[cfg(feature = "regex")]
pub use crate::regex::parse;

我使用 #[feature(prelude_import)] 可以使用 use crate_name::parse,去掉注释反而需要 use crate_name::prelude::parse.

为什么会出现这种差别

评论区

写评论
苦瓜小仔 2023-04-11 22:41

prelude_import

This feature has no tracking issue, and is therefore likely internal to the compiler, not being intended for general use.

https://doc.rust-lang.org/unstable-book/language-features/prelude-import.html

1 共 1 条评论, 1 页