如何让 rust 代码使用本地使用命令
how to let the rust code using local use command
我写了一个像这样的 rust 代码:
fn find_channel(request: &ChannelRequest) -> Box<dyn BoxableExpression<crate::model::diesel::dolphin::dolphin_schema::rss_sub_source::table, DB, SqlType=Bool> + '_> {
use crate::model::diesel::dolphin::dolphin_schema::rss_sub_source::dsl::*;
match request {
ChannelRequest { editorPick, .. } if editorPick.unwrap_or(0) == 1 => Box::new(crate::model::diesel::dolphin::dolphin_schema::rss_sub_source::dsl::editor_pick.eq(editorPick)),
ChannelRequest{ minimalReputation, ..} if minimalReputation.unwrap_or(0) > 0 => Box::new(crate::model::diesel::dolphin::dolphin_schema::rss_sub_source::dsl::reputation.gt(minimalReputation)),
_ => Box::new(crate::model::diesel::dolphin::dolphin_schema::rss_sub_source::dsl::editor_pick.eq(0))
}
}
现在我想让代码更短,并删除 crate::model::diesel::dolphin::dolphin_schema::rss_sub_source::dsl::
并想让 editor_pick
使用本地函数导入命令。令我惊讶的是,IDE 仍然告诉我要导入 crate::model::diesel::dolphin::dolphin_schema::rss_sub_source::dsl::
,为什么即使在函数中导入了还需要导入?我应该如何从代码中删除包路径并使代码更短更清晰?是否可以从代码中删除包路径?这是来自 IDE:
的智能提示
cargo
/rustc
是否接受代码?在这种情况下,IntelliJ Rust 可能存在问题。
我写了一个像这样的 rust 代码:
fn find_channel(request: &ChannelRequest) -> Box<dyn BoxableExpression<crate::model::diesel::dolphin::dolphin_schema::rss_sub_source::table, DB, SqlType=Bool> + '_> {
use crate::model::diesel::dolphin::dolphin_schema::rss_sub_source::dsl::*;
match request {
ChannelRequest { editorPick, .. } if editorPick.unwrap_or(0) == 1 => Box::new(crate::model::diesel::dolphin::dolphin_schema::rss_sub_source::dsl::editor_pick.eq(editorPick)),
ChannelRequest{ minimalReputation, ..} if minimalReputation.unwrap_or(0) > 0 => Box::new(crate::model::diesel::dolphin::dolphin_schema::rss_sub_source::dsl::reputation.gt(minimalReputation)),
_ => Box::new(crate::model::diesel::dolphin::dolphin_schema::rss_sub_source::dsl::editor_pick.eq(0))
}
}
现在我想让代码更短,并删除 crate::model::diesel::dolphin::dolphin_schema::rss_sub_source::dsl::
并想让 editor_pick
使用本地函数导入命令。令我惊讶的是,IDE 仍然告诉我要导入 crate::model::diesel::dolphin::dolphin_schema::rss_sub_source::dsl::
,为什么即使在函数中导入了还需要导入?我应该如何从代码中删除包路径并使代码更短更清晰?是否可以从代码中删除包路径?这是来自 IDE:
cargo
/rustc
是否接受代码?在这种情况下,IntelliJ Rust 可能存在问题。