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,     ); }  

相关内容

热门资讯

玩家必备科普透视挂!祺友互娱透... 玩家必备科普透视挂!祺友互娱透视挂多功能AIapp,祺友互娱都是有透视挂app1、下载好祺友互娱透视...
2024教程外挂!闲逸斗地主外... 2024教程外挂!闲逸斗地主外挂多功能AI方法,闲逸斗地主本来是有外挂方法1、让任何用户在无需闲逸斗...
玩家必看科普外挂!久久互娱外挂... 玩家必看科普外挂!久久互娱外挂多功能AI插件,久久互娱一直是有外挂插件1、久久互娱免费辅助多个强度级...
重大推荐开挂!新老夫子开挂多功... 重大推荐开挂!新老夫子开挂多功能AI技巧,新老夫子好像有开挂技巧1、让任何用户在无需新老夫子安装教程...
分享认知透视挂!君悦来透视挂多... 分享认知透视挂!君悦来透视挂多功能AI工具,君悦来确实真的是有透视挂工具1、起透看视 君悦来辅助软件...
专业讨论外挂!微乐广西麻将外挂... 专业讨论外挂!微乐广西麻将外挂多功能AI软件,微乐广西麻将其实存在有外挂软件亲,关键说明,微乐广西麻...
盘点一款作弊器!玄龙大厅作弊器... 盘点一款作弊器!玄龙大厅作弊器多功能AI工具,玄龙大厅竟然真的有作弊器工具1、实时玄龙大厅透视辅助更...
每日必看辅助!MG棋牌辅助多功... 每日必看辅助!MG棋牌辅助多功能AI教程,MG棋牌切实真的有辅助教程1、进入到MG棋牌是否有挂之后,...
玩家必备科普开挂!南京麻将开挂... 玩家必备科普开挂!南京麻将开挂多功能AI软件,南京麻将确实存在有开挂软件1、该软件可以轻松地帮助玩家...
专业讨论外挂!欢乐茶馆外挂多功... 专业讨论外挂!欢乐茶馆外挂多功能AIapp,欢乐茶馆真是是真的有外挂app欢乐茶馆破解侠是真的助透视...