Comprehensive Rust(繁体中文) 202406可讓您將函式與新型別建立關聯。您可以使用 impl 區塊來執行這項操作: struct Race { name: String, laps: Vec, } impl Race { // No receiver, a static method fn new(name: &str) -> Self { Self { name: String::from(name), laps: Vec::new() add_lap(71); race.print_laps(); race.finish(); // race.add_lap(42); } The self arguments specify the ”receiver” - the object the method acts on. There are several common receivers for a method: • &self:使用共 適用 Rust 一般借用規則:可以由一個執行緒以可變方式借用,或者由任意數量的執行緒以不可變 方式借用。 307 第 59 部分 通道 Rust 通道分為兩個部分:Sender 和 Receiver 。這兩個部分透過通道相連,但你只能看到端 點。 use std::sync::mpsc; fn main() { let (tx, rx) = mpsc::channel(); tx 0 码力 | 356 页 | 1.41 MB | 1 年前3
共 1 条
- 1













