Struct rustdoc_json::Builder
source · pub struct Builder { /* private fields */ }
Expand description
Builds rustdoc JSON. There are many build options. Refer to the docs to learn about them all. See top-level docs for an example on how to use this builder.
Implementations§
source§impl Builder
impl Builder
sourcepub fn toolchain(self, toolchain: impl Into<String>) -> Self
pub fn toolchain(self, toolchain: impl Into<String>) -> Self
Set the toolchain. Default: None
.
Until rustdoc JSON has stabilized, you will want to set this to
be "nightly"
or similar.
If the toolchain is set as None
, the current active toolchain will be used.
§Notes
The currently active toolchain is typically specified by the
RUSTUP_TOOLCHAIN
environment variable, which the rustup proxy
mechanism sets. See https://rust-lang.github.io/rustup/overrides.html
for more info on how the active toolchain is determined.
sourcepub fn clear_toolchain(self) -> Self
pub fn clear_toolchain(self) -> Self
Clear a toolchain previously set with Self::toolchain
.
sourcepub fn manifest_path(self, manifest_path: impl AsRef<Path>) -> Self
pub fn manifest_path(self, manifest_path: impl AsRef<Path>) -> Self
Set the relative or absolute path to Cargo.toml
. Default: Cargo.toml
sourcepub fn target_dir(self, target_dir: impl AsRef<Path>) -> Self
pub fn target_dir(self, target_dir: impl AsRef<Path>) -> Self
Set what --target-dir
to pass to cargo
. Typically only needed if you
want to be able to build rustdoc JSON for the same crate concurrently,
for example to parallelize regression tests.
sourcepub fn clear_target_dir(self) -> Self
pub fn clear_target_dir(self) -> Self
Clear a target dir previously set with Self::target_dir
.
sourcepub const fn quiet(self, quiet: bool) -> Self
pub const fn quiet(self, quiet: bool) -> Self
Whether or not to pass --quiet
to cargo rustdoc
. Default: false
sourcepub const fn silent(self, silent: bool) -> Self
pub const fn silent(self, silent: bool) -> Self
Whether or not to redirect stdout and stderr to /dev/null. Default: false
sourcepub const fn color(self, color: Color) -> Self
pub const fn color(self, color: Color) -> Self
Color configuration for the output of cargo rustdoc
.
sourcepub fn target(self, target: String) -> Self
pub fn target(self, target: String) -> Self
Whether or not to pass --target
to cargo rustdoc
. Default: None
sourcepub const fn no_default_features(self, no_default_features: bool) -> Self
pub const fn no_default_features(self, no_default_features: bool) -> Self
Whether to pass --no-default-features
to cargo rustdoc
. Default: false
sourcepub const fn all_features(self, all_features: bool) -> Self
pub const fn all_features(self, all_features: bool) -> Self
Whether to pass --all-features
to cargo rustdoc
. Default: false
sourcepub fn features<I: IntoIterator<Item = S>, S: AsRef<str>>(
self,
features: I,
) -> Self
pub fn features<I: IntoIterator<Item = S>, S: AsRef<str>>( self, features: I, ) -> Self
Features to pass to cargo rustdoc
via --features
. Default to an empty vector
sourcepub fn package(self, package: impl AsRef<str>) -> Self
pub fn package(self, package: impl AsRef<str>) -> Self
Package to use for cargo rustdoc
via -p
. Default: None
sourcepub fn package_target(self, package_target: PackageTarget) -> Self
pub fn package_target(self, package_target: PackageTarget) -> Self
What part of the package to document. Default: PackageTarget::Lib
sourcepub fn document_private_items(self, document_private_items: bool) -> Self
pub fn document_private_items(self, document_private_items: bool) -> Self
Whether to pass --document-private-items
to cargo rustdoc
. Default: false
sourcepub fn cap_lints(self, cap_lints: Option<impl AsRef<str>>) -> Self
pub fn cap_lints(self, cap_lints: Option<impl AsRef<str>>) -> Self
What to pass as --cap-lints
to rustdoc JSON build command
sourcepub fn build(self) -> Result<PathBuf, BuildError>
pub fn build(self) -> Result<PathBuf, BuildError>
Generate rustdoc JSON for a crate. Returns the path to the freshly built rustdoc JSON file.
This method will print the stdout and stderr of the cargo rustdoc
command to the stdout
and stderr of the calling process. If you want to capture the output, use
Builder::build_with_captured_output()
.
See top-level docs for an example on how to use it.
§Errors
E.g. if building the JSON fails or if the manifest path does not exist or is invalid.
sourcepub fn build_with_captured_output(
self,
stdout: impl Write,
stderr: impl Write,
) -> Result<PathBuf, BuildError>
pub fn build_with_captured_output( self, stdout: impl Write, stderr: impl Write, ) -> Result<PathBuf, BuildError>
Generate rustdoc JSON for a crate. This works like Builder::build()
, but will
capture the stdout and stderr of the cargo rustdoc
command. The output will be written to
the stdout
and stderr
parameters. In particular, potential warnings and errors emitted
by cargo rustdoc
will be captured to stderr
. This can be useful if you want to present
these errors to the user only when the build failed. Here’s an example of how that might
look like:
let mut stderr: Vec<u8> = Vec::new();
let result: Result<PathBuf, BuildError> = rustdoc_json::Builder::default()
.toolchain("nightly")
.manifest_path("Cargo.toml")
.build_with_captured_output(std::io::sink(), &mut stderr);
match result {
Err(BuildError::BuildRustdocJsonError) => {
eprintln!("Crate failed to build:\n{}", String::from_utf8_lossy(&stderr));
}
Err(e) => {
eprintln!("Error generating the rustdoc json: {}", e);
}
Ok(json_path) => {
// Do something with the json_path.
}
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Builder
impl RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnwindSafe for Builder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)