Comprehensive Rust(繁体中文) 202406output, applying formatting described in std::fmt. • format!(format, ..) 的運作方式與 println! 類似,但會以字串形式傳回結果。 • dbg!(expression) 會記錄並傳回運算式的值。 • todo!() 可將一小段程式碼標示為尚未實作,但執行後會發生恐慌。 • unavailable!() 可將一小段程式碼標示為無法存取,但執行後會發生恐慌。 Rust compiler provides by confirming when all cases are handled. • 將 divide_in_two 的結果儲存在 result 變數中,並在迴圈中 match 結果。由於配對符合時會 耗用 msg,因此這麼做並不會執行編譯。如要修正此問題,請配對&result,而非 result。這會讓 msg 成為參照,因此就不會遭到耗用。這個「人因工程學的配對」功能已於 } String 會實作 Deref。也就是說,您可以在 String 上呼叫所有 str 方法。 • String::new 會 傳 回 新 的 空 白 字 串,如 果 您 知 道 要 向 字 串 推 送 多 少 資 料,請 使 用 String::with_capacity。 • String::len 會傳回 String 的大小 (以位元組為單位,可能與以字元為單位的長度不同)。 0 码力 | 356 页 | 1.41 MB | 1 年前3
共 1 条
- 1













