Rust--模块
Rust中要实现多个文件来编译程序。需要学习以下内容来实现:
Rust中的组织单位是模块,就像CSharp语言中的组织单位是类
pub mod school{
pub mod teacher{
pub fn teach(){
println!("Teacher's work is teaching student");
}
}
pub mod student{
pub fn study(){
println!("Student's work is studying");
}
}
}
use school::teacher;
fn main(){
school::student::study();
teacher::teach();
}
输出结果:

标准库文件调用:
pub mod school{
pub mod teacher{
pub fn teach(){
println!("Teacher's work is teaching student");
}
}
pub mod student{
pub fn study(){
println!("Student's work is studying");
}
}
}
use school::teacher;
use std::f64::consts::PI as pi; //调用标准库文件
fn main(){
school::student::study();
teacher::teach();
println!("pi number is {}",pi);
}
输出结果:

Rust标准库:https://doc.rust-lang.org/stable/std/all.html
------------------------------------
承接
**视觉检测软件开发及调试
**工业软件开发
**上位机软件开发
wechat:luoran2024
qq:565934058
email:taoyuansu@qq.com
海量教育资源及影视资源下载
微信公众号:EFun科技
------------------------------------

浙公网安备 33010602011771号