Rust代码答疑报错|Python一对一辅导答疑
创始人
2024-12-08 21:34:20
0

Question

你好,我是悦创。

学员答疑:

在这里插入图片描述

  • https://code.bornforthis.cn/?id=4e72084d-1eaf-44ed-8067-744671491574
  • https://code.bornforthis.cn/?id=664ff169-41d6-409f-a05b-02ed42279759

问题代码:

// You can bring module paths into scopes and provide new names for them with // the `use` and `as` keywords.  #[allow(dead_code)] mod delicious_snacks {     // TODO: Add the following two `use` statements after fixing them.     use self::fruits::PEAR as fruits;     use self::veggies::CUCUMBER as veggies;      pub mod fruits {         pub const PEAR: &str = "Pear";         pub const APPLE: &str = "Apple";     }      pub mod veggies {         pub const CUCUMBER: &str = "Cucumber";         pub const CARROT: &str = "Carrot";     } }  fn main() {     println!(         "favorite snacks: {} and {}",          delicious_snacks::fruit,         delicious_snacks::veggie,     ); } 

报错:

D:\LagerA\rust\a-ex\rustlings git:[master] rustlings run modules2 error[E0425]: cannot find value `fruit` in module `delicious_snacks`   --> exercises/10_modules/modules2.rs:25:27    | 11 |         pub const PEAR: &str = "Pear";    |         ------------------------------ similarly named constant `fruits` defined here ... 25 |         delicious_snacks::fruit,    |                           ^^^^^ help: a constant with a similar name exists: `fruits`  error[E0425]: cannot find value `veggie` in module `delicious_snacks`   --> exercises/10_modules/modules2.rs:26:27    | 16 |         pub const CUCUMBER: &str = "Cucumber";    |         -------------------------------------- similarly named constant `veggies` defined here ... 26 |         delicious_snacks::veggie,    |                           ^^^^^^ help: a constant with a similar name exists: `veggies`  warning: unused import: `self::fruits::PEAR as fruits`  --> exercises/10_modules/modules2.rs:7:9   | 7 |     use self::fruits::PEAR as fruits;   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^   |   = note: `#[warn(unused_imports)]` on by default  warning: unused import: `self::veggies::CUCUMBER as veggies`  --> exercises/10_modules/modules2.rs:8:9   | 8 |     use self::veggies::CUCUMBER as veggies;    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    For more information about this error, try `rustc --explain E0425`. error: could not compile `exercises` (bin "modul es2") due to 2 previous errors; 2 warnings emitted  Error: Ran exercises/10_modules/modules2.rs with errors 

Solution

#[allow(dead_code)] mod delicious_snacks {     // 使用 `use` 语句将常量导入到模块的顶层作用域     pub use self::fruits::PEAR as fruit;     pub use self::veggies::CUCUMBER as veggie;      pub mod fruits {         pub const PEAR: &str = "Pear";         pub const APPLE: &str = "Apple";     }      pub mod veggies {         pub const CUCUMBER: &str = "Cucumber";         pub const CARROT: &str = "Carrot";     } }  fn main() {     println!(         "favorite snacks: {} and {}",         delicious_snacks::fruit,         delicious_snacks::veggie,     ); }  

相关内容

热门资讯

绝活儿辅助!广西老友玩老是输怎... 绝活儿辅助!广西老友玩老是输怎么办(辅助挂)都是真的有辅助app(讲解有挂)在进入广西老友玩老是输怎...
法门辅助!福建13水插件(辅助... 法门辅助!福建13水插件(辅助挂)一贯是有辅助技巧(有挂技术)1、许多玩家不知道福建13水插件辅助怎...
办法辅助!潮友会app下载官方... 办法辅助!潮友会app下载官方辅助器(辅助挂)真是真的是有辅助app(有挂教程)该软件可以轻松地帮助...
妙招辅助!邯郸胡乐挂辅助(辅助... 妙招辅助!邯郸胡乐挂辅助(辅助挂)好像存在有辅助插件(有挂方略)1、上手简单,内置详细流程视频教学,...
教程书辅助!乐酷辅助(辅助挂)... 教程书辅助!乐酷辅助(辅助挂)其实存在有辅助脚本(有挂细节)乐酷辅助能透视中分为三种模型:乐酷辅助模...
学习辅助!决战卡五星辅助(辅助... 学习辅助!决战卡五星辅助(辅助挂)本来真的是有辅助软件(有人有挂)学习辅助!决战卡五星辅助(辅助挂)...
绝活辅助!边锋嘉兴麻将辅助器(... 绝活辅助!边锋嘉兴麻将辅助器(辅助挂)真是真的有辅助神器(新版有挂)1、边锋嘉兴麻将辅助器公共底牌简...
举措辅助!枫叶辅助器(辅助挂)... 举措辅助!枫叶辅助器(辅助挂)本来存在有辅助技巧(竟然有挂)1、下载好枫叶辅助器正确养号方法之后点击...
讲义辅助!点我达辅助(辅助挂)... 讲义辅助!点我达辅助(辅助挂)一直存在有辅助技巧(有人有挂)1、点我达辅助辅助器安装包、点我达辅助辅...
模块辅助!威信茶馆有挂的吗(辅... 模块辅助!威信茶馆有挂的吗(辅助挂)一直真的是有辅助脚本(揭秘有挂)1、玩家可以在威信茶馆有挂的吗线...