Rust4.1 Managing Growing Projects with Packages, Crates, and Modules
Rust学习笔记
Rust编程语言入门教程课程笔记
参考教材: The Rust Programming Language (by Steve Klabnik and Carol Nichols, with contributions from the Rust Community)
Lecture 7: Managing Growing Projects with Packages, Crates, and Modules
src/main.rs
// src/main.rs: the main file of the project, where the main function is defined; this is the crate root
// src/lib.rs: the root of your crate’s library; the library’s name is the same as the name of the crate
// src/bin: directory that can contain multiple binary crates; each file in this directory will be a separate binary crate
// src/bin/main.rs: the main file of the binary crate with the same name as the directory; this file is the crate root of the binary crate//Modules
use std::collections::HashMap;// use keyword to bring module into scopeuse std::io::Result as IoResult;// use keyword to bring module into scope
use std::{cmp, io};// use keyword to bring module into scope
use rand::Rng;// use keyword to bring module into scope
use std::collections::*;// use keyword to bring module into scope, * is glob operatorfn main() {let mut map = HashMap::new();map.insert(1, 2);println!("{:?}", map);let m = IoResult::Ok(());println!("{:?}", m);let mut rng = rand::thread_rng();let t = rng.gen_range(1..=10);println!("{:?}", t);
}
src/lib.rs
mod front_of_house;//{// module// pub mod hosting{// public module// pub fn add_to_waitlist(){}// }// mod serving{// private module// fn take_order(){}// fn serve_order(){}// fn take_payment(){}// }// fn fix_incorrect_order(){// cook_order();// super::serve_order();// super keyword to access parent module// crate::serve_order();// absolute path// }// pub fn cook_order(){}// pub struct Breakfast{// pub toast: String,// seasonal_fruit: String,// }// impl Breakfast{// pub fn summer(toast: &str) -> Breakfast{// Breakfast{// toast: String::from(toast),// seasonal_fruit: String::from("peaches"),// }// }// }
//}pub use crate::front_of_house::hosting;// use keyword to bring module into scope
//use crate::front_of_house::servering;// cannot use private module
//use front_of_house::hosting;// relative pathpub fn eat_at_restaurant(){// Absolute pathcrate::front_of_house::hosting::add_to_waitlist();// Relative pathfront_of_house::hosting::add_to_waitlist();// Order a breakfast in the summer with Rye toastlet mut meal = front_of_house::Breakfast::summer("Rye");// Change our mind about what bread we'd likemeal.toast = String::from("Wheat");println!("I'd like {} toast please", meal.toast);// The next line won't compile if we uncomment it; we're not allowed// to see or modify the seasonal fruit that comes with the meal// meal.seasonal_fruit = String::from("blueberries");hosting::add_to_waitlist();}fn serve_order(){}
src/front_of_house.rs
pub mod hosting; //{// public module
// pub fn add_to_waitlist(){}
// }mod serving{// private modulefn take_order(){}fn serve_order(){}fn take_payment(){}
}fn fix_incorrect_order(){cook_order();super::serve_order();// super keyword to access parent modulecrate::serve_order();// absolute path
}pub fn cook_order(){}pub struct Breakfast{pub toast: String,seasonal_fruit: String,
}impl Breakfast{pub fn summer(toast: &str) -> Breakfast{Breakfast{toast: String::from(toast),seasonal_fruit: String::from("peaches"),}}
}
src/front_of_house/hosting.rs
pub fn add_to_waitlist(){}
相关文章:
Rust4.1 Managing Growing Projects with Packages, Crates, and Modules
Rust学习笔记 Rust编程语言入门教程课程笔记 参考教材: The Rust Programming Language (by Steve Klabnik and Carol Nichols, with contributions from the Rust Community) Lecture 7: Managing Growing Projects with Packages, Crates, and Modules src/main.rs // s…...
RPA在财务预测和分析中的应用
在现代企业管理中,财务数据分析是决策制定和战略规划的关键环节。大数据的兴起带来财务数据的复杂性和数量不断增加,企业为此消耗了大量人力和物力。随着当今数字化、智能化时代的到来,越来越多企业引进RPA技术来提高工作效率,实现…...

无人机航拍技术基础入门,无人机拍摄的方法与技巧
一、教程描述 买了无人机,可是我不敢飞怎么办?禁飞区越来越多,到底哪儿才能飞?我的无人机跟你一样,为什么我拍不出大片?厂家的说明书看不进去,有没有一套无人机的课程,可以快速上手…...
PTA 哈密尔回路(建图搜索)
题目 著名的“汉密尔顿(Hamilton)回路问题”是要找一个能遍历图中所有顶点的简单回路(即每个顶点只访问 1 次)。本题就要求你判断任一给定的回路是否汉密尔顿回路。 输入格式: 首先第一行给出两个正整数:…...

如何利用产品帮助中心提升用户体验
在当今竞争激烈的市场中,提供优秀的用户体验是吸引和保留客户的关键。而一个高效和易于使用的产品帮助中心,正成为越来越多企业用以提升用户体验的重要工具。产品帮助中心是一个集中的信息库,为用户提供关于产品功能、故障排除、常见问题解答…...

【Python大数据笔记_day05_Hive基础操作】
一.SQL,Hive和MapReduce的关系 用户在hive上编写sql语句,hive把sql语句转化为MapReduce程序去执行 二.Hive架构映射流程 用户接口: 包括CLI、JDBC/ODBC、WebGUI,CLI(command line interface)为shell命令行;Hive中的Thrift服务器允许外部客户端…...

css呼吸效果实现
实现一个图片有规律的大小变化,呈现呼吸效果,怎么用CSS实现这个呼吸效果呢 一.实现 CSS实现动态效果可以使用动画( animation)来属性实现,放大缩小效果可以用transform: scale来实现,在这基础上有了动画,就可以设置一个…...

机器视觉opencv答题卡识别系统 计算机竞赛
0 前言 🔥 优质竞赛项目系列,今天要分享的是 🚩 答题卡识别系统 - opencv python 图像识别 该项目较为新颖,适合作为竞赛课题方向,学长非常推荐! 🥇学长这里给一个题目综合评分(每项满分5分…...
2024年的后端和Web开发趋势
目录 1 2 3 4 5 1 不断变化的数字创新格局可能让人感觉像是一场无情的竞赛。作为开发人员,你的痛苦是真实的——交付尖端产品、保持竞争力、跟上不断变化的用户期望,综合起来你的压力可能是压倒性的。 但是,如果我们告诉你有一个指南针…...

对比了10+网盘资源搜索工具,我最终选择了这款爆赞的阿里云盘、百度网盘、夸克网盘资源一站式搜索工具
盘友圈(https://panyq.com)是一个综合性的网盘搜索站,与其他网盘搜索工具相比,它具有多个独特的优点,使其成为用户们首选的平台。 首先,盘友圈汇集了阿里云盘、百度网盘和夸克网盘等主流网盘资源ÿ…...

GoLong的学习之路(二十)进阶,语法之反射(reflect包)
这个是为了接上之前的语法篇的。按照我的学习计划,这里此时应该有一个小项目来做一个统合。但是吧,突然觉得,似乎也没必要。能学go的大部分肯定都是有其他语言的基础的。 接下来说反射 文章目录 反射介绍reflect包TypeOftype name和type kin…...
关于表单校验,:rules=“loginRules“
在写好validator相关的方法后,rule测试没有生效 <el-form ref"loginForm" :model"loginForm" :rules"loginRules" class"login-form" <el-form-item prop"username"> <el-input ref"usernam…...

统一消息分发中心设计
背景 我们核心业务中订单完成时,需要完成后续的连带业务,扣件库存库存、增加积分、通知商家等。 如下图的架构: 这样设计出来导致我们的核心业务和其他业务耦合,每次新增连带业务或者去掉连带业务都需要修改核心业务。 一方面&…...

前端项目导入vue和element
1.安装nodejs 下载链接https://cdn.npmmirror.com/binaries/node/v18.18.0/node-v18.18.0-x64.msi 进入cmd 命令行模式 管理员身份运行 输入 (node -v)能看到版本号 npm config set prefix "C:\Program Files\nodejs" 默认路径 npm config…...

【11】使用透视投影建立一个3D空间的测试
核心操作: 1.proj view model 这三个矩阵 glm::mat4 mvp m_Proj * m_View * model; m_Shader->Bind(); m_Shader->SetUniformMat4f("u_MVP", mvp);着色器里面就: proj:投影矩阵,可以选择正交投影,或者透视投影…...

【广州华锐互动】VR影视制片虚拟仿真教学系统
随着虚拟现实(VR)技术的不断发展,VR在影视制片教学中的应用场景也变得越来越丰富。本文将介绍VR在影视制片教学中的常见应用场景及其意义,并通过案例分析来更好地展示其应用前景。 在影视制片教学中,VR可以提供一种沉浸式的制作体验。其中&am…...

从研发域到量产域的自动驾驶工具链探索与实践
导读 本文整理自 2023 年 9 月 5 日百度云智大会 - 智能汽车分论坛,百度智能云自动驾驶云研发高级经理徐鹏的主题演讲《从研发域到量产域的自动驾驶工具链探索与实践》。 全文中部段落附有演讲中 2 个产品演示视频的完整版,精彩不容错过。 (视频观看&…...
404. 左叶子之和
原题链接:404. 左叶子之和 思路: 首先要注意是判断左叶子,不是二叉树左侧节点,所以不要上来想着层序遍历。 节点A的左孩子不为空,且左孩子的左右孩子都为空(说明是叶子节点),那么A节…...

基于SSM的课程管理系统
末尾获取源码 开发语言:Java Java开发工具:JDK1.8 后端框架:SSM 前端:Vue 数据库:MySQL5.7和Navicat管理工具结合 服务器:Tomcat8.5 开发软件:IDEA / Eclipse 是否Maven项目:是 目录…...

【hcie-cloud】【5】华为云Stack规划设计之华为云Stack标准化配置、缩略语【下】
文章目录 前言、华为云Stack交付综述为云Stack标准组网华为云Stack标准化配置华为云Stack配置概览华为云Stack云服务全视图华为云Stack部署方案节点类型说明华为云Stack云服务组件部署场景管理节点部署原则云平台管理规格华为云Stack IaaS场景&高阶场景起步必选部署组件x86…...

多模态2025:技术路线“神仙打架”,视频生成冲上云霄
文|魏琳华 编|王一粟 一场大会,聚集了中国多模态大模型的“半壁江山”。 智源大会2025为期两天的论坛中,汇集了学界、创业公司和大厂等三方的热门选手,关于多模态的集中讨论达到了前所未有的热度。其中,…...

2.Vue编写一个app
1.src中重要的组成 1.1main.ts // 引入createApp用于创建应用 import { createApp } from "vue"; // 引用App根组件 import App from ./App.vue;createApp(App).mount(#app)1.2 App.vue 其中要写三种标签 <template> <!--html--> </template>…...
MySQL用户和授权
开放MySQL白名单 可以通过iptables-save命令确认对应客户端ip是否可以访问MySQL服务: test: # iptables-save | grep 3306 -A mp_srv_whitelist -s 172.16.14.102/32 -p tcp -m tcp --dport 3306 -j ACCEPT -A mp_srv_whitelist -s 172.16.4.16/32 -p tcp -m tcp -…...

华硕a豆14 Air香氛版,美学与科技的馨香融合
在快节奏的现代生活中,我们渴望一个能激发创想、愉悦感官的工作与生活伙伴,它不仅是冰冷的科技工具,更能触动我们内心深处的细腻情感。正是在这样的期许下,华硕a豆14 Air香氛版翩然而至,它以一种前所未有的方式&#x…...
python报错No module named ‘tensorflow.keras‘
是由于不同版本的tensorflow下的keras所在的路径不同,结合所安装的tensorflow的目录结构修改from语句即可。 原语句: from tensorflow.keras.layers import Conv1D, MaxPooling1D, LSTM, Dense 修改后: from tensorflow.python.keras.lay…...

推荐 github 项目:GeminiImageApp(图片生成方向,可以做一定的素材)
推荐 github 项目:GeminiImageApp(图片生成方向,可以做一定的素材) 这个项目能干嘛? 使用 gemini 2.0 的 api 和 google 其他的 api 来做衍生处理 简化和优化了文生图和图生图的行为(我的最主要) 并且有一些目标检测和切割(我用不到) 视频和 imagefx 因为没 a…...

MFC 抛体运动模拟:常见问题解决与界面美化
在 MFC 中开发抛体运动模拟程序时,我们常遇到 轨迹残留、无效刷新、视觉单调、物理逻辑瑕疵 等问题。本文将针对这些痛点,详细解析原因并提供解决方案,同时兼顾界面美化,让模拟效果更专业、更高效。 问题一:历史轨迹与小球残影残留 现象 小球运动后,历史位置的 “残影”…...
解决:Android studio 编译后报错\app\src\main\cpp\CMakeLists.txt‘ to exist
现象: android studio报错: [CXX1409] D:\GitLab\xxxxx\app.cxx\Debug\3f3w4y1i\arm64-v8a\android_gradle_build.json : expected buildFiles file ‘D:\GitLab\xxxxx\app\src\main\cpp\CMakeLists.txt’ to exist 解决: 不要动CMakeLists.…...

Chromium 136 编译指南 Windows篇:depot_tools 配置与源码获取(二)
引言 工欲善其事,必先利其器。在完成了 Visual Studio 2022 和 Windows SDK 的安装后,我们即将接触到 Chromium 开发生态中最核心的工具——depot_tools。这个由 Google 精心打造的工具集,就像是连接开发者与 Chromium 庞大代码库的智能桥梁…...
掌握 HTTP 请求:理解 cURL GET 语法
cURL 是一个强大的命令行工具,用于发送 HTTP 请求和与 Web 服务器交互。在 Web 开发和测试中,cURL 经常用于发送 GET 请求来获取服务器资源。本文将详细介绍 cURL GET 请求的语法和使用方法。 一、cURL 基本概念 cURL 是 "Client URL" 的缩写…...