2016-02-21 74 views

回答

5

你唯一能做的就是隱藏這樣的「內部」符號,使它們不會出現在文檔中。例如:

#[macro_export] 
macro_rules! custom_abort { 
    ($($args:tt)*) => { 
     match format!($($args)*) { 
      msg => $crate::custom_abort__(&msg) 
     } 
    }; 
} 

/// This is an implementation detail and *should not* be called directly! 
#[doc(hidden)] 
pub fn custom_abort__(msg: &str) -> ! { 
    use std::io::Write; 
    let _ = writeln!(std::io::stderr(), "{}", msg); 
    std::process::exit(1); 
} 

正如您所料,這絕對防止直接調用custom_abort__人。但是,如果有人忽略了評論中的警告,並且無論如何都會這樣做,那麼當他們的代碼被破壞時,可以隨意嘲笑他們。

+1

*隨時嘲笑他們* - 等等,有沒有一段時間我不應該嘲笑使用我的代碼的人? ;-) – Shepmaster

相關問題