Jiang's Tech Journal

Jiang's Tech Journal

首页
分类
关于
Login →
Jiang's Tech Journal

Jiang's Tech Journal

首页 分类 关于
Login
  1. Home
  2. Rust
  3. [Rust] 模块与文件分离

[Rust] 模块与文件分离

0
  • Rust
  • Published at 2025-02-23
  • Read 44 times
Jiang
Jiang
Table of Contents
No Table of Contents

我们可以让模块不再平铺在目录里面,把他移入文件文件夹中。

src
├── front_of_house
│   └── hosting.rs
├── front_of_house.rs
└── lib.rs
//lib.rs
mod front_of_house;//导入当前目录下的front_of_house.rs文件
pub use crate::front_of_house::hosting;//导入其中的方法

pub fn eat_at_restaurant() {
    hosting::add_to_waitlist();
    hosting::add_to_waitlist();
    hosting::add_to_waitlist();
}
//front_of_house.rs与模块名同名文件夹下的方法名.rs文件
pub mod hosting; //导入文件 文件夹里有多少可以导入多少
//front_of_house/hosting.rs
pub fn add_to_waitlist() {
    //具体实现
}

Related Posts

[Rust] Rust语言圣经

https://course.rs/

[Rust] 模块与文件分离

我们可以让模块不再平铺在目录里面,把他移入文件文件夹中。 src ├── front_of_house │ └── hosting.rs ├── front_of_house.rs └── lib.rs //lib.rs mod front_of_house;//导入当前目录下的front_of

[Rust] 多线程并发访问

// main.rs use futures::future::join_all; use reqwest::Client; use std::sync::Arc; use tokio::sync::Semaphore; use tokio::task; // 引入join_all #[tokio

Table of Contents
No Table of Contents
Copyright © 2024 your company All Rights Reserved. Powered by Halo.