devela::all

Function crate_root

Source
pub fn crate_root<P: AsRef<Path>>(path: P) -> Result<PathBuf>
Available on crate feature std only.
Expand description

Returns an absolute PathBuf, relative to the crate’s root.

It determines the root by finding the first Cargo.toml file, from the current directory through its ancestors.

§Errors

Returns an error if it can’t find any Cargo.toml file, or if it encounters an invalid path during the search process.

§Examples

use devela::sys::crate_root;

match crate_root("") {
    Ok(p) => println!("Current crate root is {:?}", p),
    Err(e) => println!("Error obtaining crate root {:?}", e)
};