当前位置: 首页 > news >正文

Rust代码答疑报错|Python一对一辅导答疑

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

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • sql查询报错空指针怎么解决?
  • Anything LLM ,构建自己的 RAG 架构 LLM,学习自己的知识库
  • HCIP之PPP协议(PAP认证,CHAP认证)、GRE、MGRE综合实验
  • git -.gitignore不生效的问题
  • React 18【实用教程】(2024最新版)
  • 从dev分支合并到master分支
  • Vue 3项目安装Element-Plus
  • el-table表格 及其el-pagination分页 封装及其使用
  • 【深度学习】sdxl的Lora训练技巧
  • day07:用户下单、订单支付
  • JUnit 单元测试
  • three完全开源扩展案例05-围栏着色器
  • 微信小程序 - 在视图组件上绑定函数并携带参数(事件对象自定义属性传参)
  • mysql-造数据/列转行
  • Tomcat部署、优化、压力测试
  • [原]深入对比数据科学工具箱:Python和R 非结构化数据的结构化
  • Android 控件背景颜色处理
  • Javascript编码规范
  • Java-详解HashMap
  • leetcode388. Longest Absolute File Path
  • Meteor的表单提交:Form
  • NSTimer学习笔记
  • Vue.js 移动端适配之 vw 解决方案
  • Web设计流程优化:网页效果图设计新思路
  • 搭建gitbook 和 访问权限认证
  • 复杂数据处理
  • 基于Mobx的多页面小程序的全局共享状态管理实践
  • 设计模式 开闭原则
  • 世界编程语言排行榜2008年06月(ActionScript 挺进20强)
  • 文本多行溢出显示...之最后一行不到行尾的解决
  • 学习JavaScript数据结构与算法 — 树
  • RDS-Mysql 物理备份恢复到本地数据库上
  • TPG领衔财团投资轻奢珠宝品牌APM Monaco
  • 哈罗单车融资几十亿元,蚂蚁金服与春华资本加持 ...
  • ​LeetCode解法汇总2182. 构造限制重复的字符串
  • ​马来语翻译中文去哪比较好?
  • ​一帧图像的Android之旅 :应用的首个绘制请求
  • ​中南建设2022年半年报“韧”字当头,经营性现金流持续为正​
  • #Spring-boot高级
  • #考研#计算机文化知识1(局域网及网络互联)
  • #中的引用型是什么意识_Java中四种引用有什么区别以及应用场景
  • (1)bark-ml
  • (13)Latex:基于ΤΕΧ的自动排版系统——写论文必备
  • (52)只出现一次的数字III
  • (HAL)STM32F103C6T8——软件模拟I2C驱动0.96寸OLED屏幕
  • (html5)在移动端input输入搜索项后 输入法下面为什么不想百度那样出现前往? 而我的出现的是换行...
  • (python)数据结构---字典
  • (附源码)ssm考生评分系统 毕业设计 071114
  • (附源码)计算机毕业设计SSM基于健身房管理系统
  • (函数)颠倒字符串顺序(C语言)
  • (九)One-Wire总线-DS18B20
  • (免费领源码)Java#ssm#MySQL 创意商城03663-计算机毕业设计项目选题推荐
  • (三)Pytorch快速搭建卷积神经网络模型实现手写数字识别(代码+详细注解)
  • (一)【Jmeter】JDK及Jmeter的安装部署及简单配置
  • (已解决)报错:Could not load the Qt platform plugin “xcb“