Comprehensive Rust(繁体中文) 202406("picked a tuple: {:?}", pick(28, ("dog", 1), ("cat", 2))); } • Rust 會根據引數型別和傳回的值來推斷 T 的型別。 • 這與 C++ 模板 (template) 類似,但 Rust 會立即對泛型函式進行部分編譯,因此函式必須適用於所 有符合限制條件的型別。舉例來說,如果 n == 0,請嘗試修改 pick 以傳回 even + odd。即使只 that don't depend on libc, allocator or even the presence of an operating system. • alloc 包括需要全域堆積配置器的型別,例如 Vec、Box 和 Arc。 • 嵌入式 Rust 應用程式通常只使用 core,偶爾會使用 alloc。 16.2 說明文件測試 Rust 說明文件的主題涵蓋甚廣,包括: • help functional- style programming. • Result 是實作錯誤處理的標準型別,我們將在第 3 天的課程中介紹。 16.5 String String 是標準堆積配置的可成長 UTF-8 字串緩衝區: fn main() { let mut s1 = String::new(); s1.push_str("Hello"); println!("s1: len0 码力 | 356 页 | 1.41 MB | 1 年前3
共 1 条
- 1













