pub fn build_doc(name: &str, vers: Option<&str>, target: Option<&str>) -> Result<Package> {
    let config = try!(Config::default());
    let source_id = try!(SourceId::crates_io(&config));

    let source_map = try!(SourceConfigMap::new(&config));
    let mut source = try!(source_map.load(&source_id));

    // update crates.io-index registry
    try!(source.update());

    let dep = try!(Dependency::parse_no_deprecated(name, vers, &source_id));
    let deps = try!(source.query(&dep));
    let pkg = try!(deps.iter().map(|p| p.package_id()).max()
                   // FIXME: This is probably not a rusty way to handle options and results
                   //        or maybe it is who knows...
                   .map(|pkgid| source.download(pkgid))
                   .unwrap_or(Err(human("PKG download error"))));

    let current_dir = try!(env::current_dir());
    let target_dir = PathBuf::from(current_dir).join("cratesfyi");

    let metadata = Metadata::from_package(&pkg).map_err(|e| human(e.description()))?;

    // This is only way to pass rustc_args to cargo.
    // CompileOptions::target_rustc_args is used only for the current crate,
    // and since docs.rs never runs rustc on the current crate, we assume rustc_args
    // will be used for the dependencies. That is why we are creating RUSTFLAGS environment
    // variable instead of using target_rustc_args.
    if let Some(rustc_args) = metadata.rustc_args {
        env::set_var("RUSTFLAGS", rustc_args.join(" "));
    }

    // since https://github.com/rust-lang/rust/pull/48511 we can pass --resource-suffix to
    // add correct version numbers to css and javascript files
    let mut rustdoc_args: Vec<String> =
        vec!["-Z".to_string(), "unstable-options".to_string(),
             "--resource-suffix".to_string(),
             format!("-{}", parse_rustc_version(get_current_versions()?.0)?)];
    if let Some(package_rustdoc_args) = metadata.rustdoc_args {
        rustdoc_args.append(&mut package_rustdoc_args.iter().map(|s| s.to_owned()).collect());
    }

    let opts = ops::CompileOptions {
        config: &config,
        jobs: None,
        target: target,
        features: &metadata.features.unwrap_or(Vec::new()),
        all_features: metadata.all_features,
        no_default_features: metadata.no_default_features,
        spec: Packages::Packages(&[]),
        mode: ops::CompileMode::Doc { deps: false },
        release: false,
        message_format: ops::MessageFormat::Human,
        filter: ops::CompileFilter::new(true,
                                        &[], false,
                                        &[], false,
                                        &[], false,
                                        &[], false),
        target_rustc_args: None,
        target_rustdoc_args: Some(rustdoc_args.as_slice()),
    };

    let ws = try!(Workspace::ephemeral(pkg, &config, Some(Filesystem::new(target_dir)), false));
    try!(ops::compile_ws(&ws, Some(source), &opts, Arc::new(DefaultExecutor)));

    Ok(try!(ws.current()).clone())
}
/// Builds documentation of a crate and version.
///
/// Crate will be built into current working directory/crate-version.
///
/// It will build latest version, if no version is given.
// idea is to make cargo to download
// and build a crate and its documentation
// instead of doing it manually like in the previous version of cratesfyi
Builds documentation of a crate and version.
Crate will be built into current working directory/crate-version.

It will build latest version, if no version is given.
idea is to make cargo to download
and build a crate and its documentation
instead of doing it manually like in the previous version of cratesfyi
Builds documentation of a crate and version . Crate will be built into current working directory / crate - version . It will build latest version if no version is given . idea is to make cargo to download and build a crate and its documentation instead of doing it manually like in the previous version of cratesfyi
pub fn build_doc(name: &str, vers: Option<&str>, target: Option<&str>) -> Result<Package> {
    let config = try!(Config::default());
    let source_id = try!(SourceId::crates_io(&config));
    let source_map = try!(SourceConfigMap::new(&config));
    let mut source = try!(source_map.load(&source_id));
    // update crates.io-index registry
    try!(source.update());
    let dep = try!(Dependency::parse_no_deprecated(name, vers, &source_id));
    let deps = try!(source.query(&dep));
    let pkg = try!(deps.iter().map(|p| p.package_id()).max()
                   // FIXME: This is probably not a rusty way to handle options and results
                   //        or maybe it is who knows...
                   .map(|pkgid| source.download(pkgid))
                   .unwrap_or(Err(human("PKG download error"))));
    let current_dir = try!(env::current_dir());
    let target_dir = PathBuf::from(current_dir).join("cratesfyi");
    let metadata = Metadata::from_package(&pkg).map_err(|e| human(e.description()))?;
    // This is only way to pass rustc_args to cargo.
    // CompileOptions::target_rustc_args is used only for the current crate,
    // and since docs.rs never runs rustc on the current crate, we assume rustc_args
    // will be used for the dependencies. That is why we are creating RUSTFLAGS environment
    // variable instead of using target_rustc_args.
    if let Some(rustc_args) = metadata.rustc_args {
        env::set_var("RUSTFLAGS", rustc_args.join(" "));
    }
    // since https://github.com/rust-lang/rust/pull/48511 we can pass --resource-suffix to
    // add correct version numbers to css and javascript files
    let mut rustdoc_args: Vec<String> =
        vec!["-Z".to_string(), "unstable-options".to_string(),
             "--resource-suffix".to_string(),
             format!("-{}", parse_rustc_version(get_current_versions()?.0)?)];
    if let Some(package_rustdoc_args) = metadata.rustdoc_args {
        rustdoc_args.append(&mut package_rustdoc_args.iter().map(|s| s.to_owned()).collect());
    }
    let opts = ops::CompileOptions {
        config: &config,
        jobs: None,
        target: target,
        features: &metadata.features.unwrap_or(Vec::new()),
        all_features: metadata.all_features,
        no_default_features: metadata.no_default_features,
        spec: Packages::Packages(&[]),
        mode: ops::CompileMode::Doc { deps: false },
        release: false,
        message_format: ops::MessageFormat::Human,
        filter: ops::CompileFilter::new(true,
                                        &[], false,
                                        &[], false,
                                        &[], false,
                                        &[], false),
        target_rustc_args: None,
        target_rustdoc_args: Some(rustdoc_args.as_slice()),
    };
    let ws = try!(Workspace::ephemeral(pkg, &config, Some(Filesystem::new(target_dir)), false));
    try!(ops::compile_ws(&ws, Some(source), &opts, Arc::new(DefaultExecutor)));
    Ok(try!(ws.current()).clone())
}
pub fn build_doc ( name : & str , vers : Option < & str > , target : Option < & str > ) -> Result < Package > { let config = try ! ( Config default ( ) ) ; let source_id = try ! ( SourceId crates_io ( config ) ) ; let source_map = try ! ( SourceConfigMap new ( config ) ) ; let mut source = try ! ( source_map load ( source_id ) ) ; // update crates.io-index registry try ! ( source update ( ) ) ; let dep = try ! ( Dependency parse_no_deprecated ( name vers source_id ) ) ; let deps = try ! ( source query ( dep ) ) ; let pkg = try ! ( deps iter ( ) map ( p p package_id ( ) ) max ( ) // FIXME: This is probably not a rusty way to handle options and results //        or maybe it is who knows... map ( pkgid source download ( pkgid ) ) unwrap_or ( Err ( human ( " " ) ) ) ) ; let current_dir = try ! ( env current_dir ( ) ) ; let target_dir = PathBuf :: from ( current_dir ) . join ( " " ) ; let metadata = Metadata :: from_package ( & pkg ) . map_err ( | e | human ( e . description ( ) ) ) ? ; // This is only way to pass rustc_args to cargo. // CompileOptions::target_rustc_args is used only for the current crate, // and since docs.rs never runs rustc on the current crate, we assume rustc_args // will be used for the dependencies. That is why we are creating RUSTFLAGS environment // variable instead of using target_rustc_args. if let Some ( rustc_args ) = metadata . rustc_args { env :: set_var ( " " , rustc_args . join ( " " ) ) ; } // since https://github.com/rust-lang/rust/pull/48511 we can pass --resource-suffix to // add correct version numbers to css and javascript files let mut rustdoc_args : Vec < String > = vec ! [ " " to_string ( ) " " to_string ( ) " " to_string ( ) format ( " " parse_rustc_version ( get_current_versions ( ) 0 ) ) ] ; if let Some ( package_rustdoc_args ) = metadata . rustdoc_args { rustdoc_args . append ( & mut package_rustdoc_args . iter ( ) . map ( | s | s . to_owned ( ) ) . collect ( ) ) ; } let opts = ops :: CompileOptions { config : & config , jobs : None , target : target , features : & metadata . features . unwrap_or ( Vec :: new ( ) ) , all_features : metadata . all_features , no_default_features : metadata . no_default_features , spec : Packages :: Packages ( & [ ] ) , mode : ops :: CompileMode :: Doc { deps : false } , release : false , message_format : ops :: MessageFormat :: Human , filter : ops :: CompileFilter :: new ( true , & [ ] , false , & [ ] , false , & [ ] , false , & [ ] , false ) , target_rustc_args : None , target_rustdoc_args : Some ( rustdoc_args . as_slice ( ) ) , } ; let ws = try ! ( Workspace ephemeral ( pkg config Some ( Filesystem new ( target_dir ) ) false ) ) ; try ! ( ops compile_ws ( ws Some ( source ) opts Arc new ( DefaultExecutor ) ) ) ; Ok ( try ! ( ws current ( ) ) . clone ( ) ) }
Builds documentation of a crate and version.
Builds documentation of a crate and version .
name
&str
vers
Option<&str>
target
Option<&str>