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

相关内容

热门资讯

玩家科普!湖南赣湘互娱辅助,新... 玩家科普!湖南赣湘互娱辅助,新道游辅助软件,机巧教程(有挂规律)1、打开软件启动之后找到中间准星的标...
总算清楚!哈糖大菠萝怎么挂,科... 总算清楚!哈糖大菠萝怎么挂,科乐天天踢有没有挂作必弊,窍要教程(有挂秘诀)科乐天天踢有没有挂作必弊是...
窍门辅助!hhpoker软件安... 窍门辅助!hhpoker软件安装包,wepoker辅助器安装包,普及教程(有挂秘诀)1、wepoke...
最新技巧!蜀山四川智能辅助插件... 最新技巧!蜀山四川智能辅助插件,哥哥打大a有辅助吗,学习教程(有挂方式)1、下载好蜀山四川智能辅助插...
妙招辅助!pokernow辅助... 妙招辅助!pokernow辅助工具,wepoker科技辅助器,开挂教程(有挂攻略)妙招辅助!poke...
发现玩家!wepoker专用辅... 发现玩家!wepoker专用辅助程序,闲逸辅助脚本,窍门教程(有挂实锤)所有人都在同一条线上,像星星...
于此同时!aa poker透视... 于此同时!aa poker透视软件,欢乐情怀开挂,妙招教程(有挂攻略)暗藏猫腻,小编详细说明欢乐情怀...
积累辅助!hhpoker有没有... 积累辅助!hhpoker有没有外挂,大菠萝辅助器,解迷教程(有挂秘籍)1、全新机制【hhpoker有...
一分钟带你了解!赣湘互娱怎么下... 一分钟带你了解!赣湘互娱怎么下载辅助,潮汕激k脚本,积累教程(真是有挂)1、赣湘互娱怎么下载辅助公共...
三分钟了解!佛手十三道辅助,来... 三分钟了解!佛手十三道辅助,来物局怎么开挂,窍门教程(果真有挂)来物局怎么开挂辅助器是一种具有地方特...