Rustdoc
Rustdoc เป็นเครื่องมือสร้าง documentation ที่มากับ Rust ที่ทรงพลังมาก สามารถสร้าง HTML docs จาก comments ใน code ได้เลย และที่สำคัญที่สุดคือ code examples ใน docs จะถูก test ด้วย cargo test!
หัวข้อหลัก: Documentation Comments
Section titled “หัวข้อหลัก: Documentation Comments”Doc Comments พื้นฐาน
Section titled “Doc Comments พื้นฐาน”// ============================================// /// = Outer doc comment// ใช้ document item ที่อยู่ถัดไป (function, struct, etc.)// ============================================/// This is a doc comment for the function below.////// It supports **markdown** formatting!////// # Examples////// ```/// let result = add(2, 3);/// assert_eq!(result, 5);/// ```fn add(a: i32, b: i32) -> i32 { a + b}
// ============================================// //! = Inner doc comment// ใช้ document item ที่ล้อมรอบอยู่ (module, crate)// ============================================//! This is a module-level doc comment.//! It documents the module itself, not the next item.
fn main() { println!("=== Doc Comment Types ===\n");
println!("/// - Outer doc comment (สำหรับ item ถัดไป)"); println!("//! - Inner doc comment (สำหรับ module/crate ที่ล้อมรอบ)"); println!(); println!("/** */ - Block doc (outer)"); println!("/*! */ - Block doc (inner)");}เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม
ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด
Login with Google