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