2016-02-21 70 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

相关问题