Function home::cargo_home [−][src]
pub fn cargo_home() -> Result<PathBuf>
Returns the storage directory used by Cargo, often knowns as
.cargo or CARGO_HOME.
It returns one of the following values, in this order of preference:
- The value of the
CARGO_HOMEenvironment variable, if it is an absolute path. - The value of the current working directory joined with the value
of the
CARGO_HOMEenvironment variable, ifCARGO_HOMEis a relative directory. - The
.cargodirectory in the user’s home directory, as reported by thehome_dirfunction.
Errors
This function fails if it fails to retrieve the current directory, or if the home directory cannot be determined.
Examples
match home::cargo_home() { Ok(path) => println!("{}", path.display()), Err(err) => eprintln!("Cannot get your cargo home dir: {:?}", err), }