Add `extern_` method to `Rustdoc`

This commit is contained in:
Guillaume Gomez 2024-05-11 20:52:10 +02:00
parent 0761802e50
commit 0712ae865f
1 changed files with 15 additions and 0 deletions

View File

@ -45,6 +45,21 @@ impl Rustdoc {
Self { cmd, stdin: None }
}
/// Specify where an external library is located.
pub fn extern_<P: AsRef<Path>>(&mut self, crate_name: &str, path: P) -> &mut Self {
assert!(
!crate_name.contains(|c: char| c.is_whitespace() || c == '\\' || c == '/'),
"crate name cannot contain whitespace or path separators"
);
let path = path.as_ref().to_string_lossy();
self.cmd.arg("--extern");
self.cmd.arg(format!("{crate_name}={path}"));
self
}
/// Specify path to the input file.
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg(path.as_ref());