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

相关内容

热门资讯

黑科技辅助(云扑克透视)外挂透... 黑科技辅助(云扑克透视)外挂透明挂辅助黑科技(透视)高科技教程(2026已更新)(哔哩哔哩);1、点...
黑科技最新!wpk专用辅助程序... 黑科技最新!wpk专用辅助程序(透视)切实有挂(有挂分析)-哔哩哔哩;亲,有的,ai轻松简单,又可以...
黑科技辅助挂!wpk有挂,太坑... 黑科技辅助挂!wpk有挂,太坑了素来真的是有挂(详细透视ai智能辅助ai)-哔哩哔哩是一款可以让一直...
黑科技辅助!wepoke是有挂... 黑科技辅助!wepoke是有挂,红龙扑克发牌有问题,必胜教程(有挂秘诀)-哔哩哔哩;1.红龙扑克发牌...
黑科技辅助(德扑之星透明)外挂... 黑科技辅助(德扑之星透明)外挂透明挂辅助黑科技(透视)必胜教程(2023已更新)(哔哩哔哩);1、不...
黑科技真的!wepoke存在外... 黑科技真的!wepoke存在外挂么(透视)一向有挂(有挂技巧)-哔哩哔哩;wepoke存在外挂么简单...
黑科技辅助挂!wpk大厅是机器... 黑科技辅助挂!wpk大厅是机器人,太坑了最初有挂(详细透视ai智能辅助软件)-哔哩哔哩;人气非常高,...
黑科技辅助!wepokeai代... 您好,wepoke透明挂辅助这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多...
黑科技辅助(WePoKe辅助插... 黑科技辅助(WePoKe辅助插件安装)外挂透明挂辅助神器(透视)2025新版教程(2021已更新)(...
黑科技app!系统规律(透视)... 黑科技app!系统规律(透视)确实是有挂(有挂详细)-哔哩哔哩;致您一封信;亲爱系统规律玩家:《系统...