#package #path #cargo

package_own

Search cargo package path

3 releases

0.0.3 Nov 10, 2019
0.0.2 Nov 10, 2019
0.0.1 Nov 9, 2019

#2619 in Development tools

MIT license

4KB
59 lines

Purpose

  • When installed from cargo install, find the folder where the installation package is located.

Usage1 (Search own local package)

use package_own::parent_folder;

fn main() {
    println!("{:?}", parent_folder(""));
}

Output1 (Return type: std::path::PathBuf)

 # Your OS: Windows

 > "{%USERPROFILE%}\\.cargo\\registry\\src\\github.com-{random number}\\
    {Your package. Case of this library<package_own-(version)>}\\"

 # Your OS: Linux

 $ "{$home}/.cargo/registry/src/github.com-{random number}/
    {Your package. Case of this library<package_own-(version)>}/"

Usage2 (Add an arbitrary path to the searched package path)

use package_own::parent_folder;

fn main() {
    println!("{:?}", parent_folder("src/main.rs"));
}

Output2 (Return type: std::path::PathBuf)

 # Your OS: Windows

 > "{%USERPROFILE%}\\.cargo\\registry\\src\\github.com-{random number}\\
    {Your package. Case of this library<package_own-(version)>}\\src\\main.rs"

 # Your OS: Linux

 $ "{$home}/.cargo/registry/src/github.com-{random number}/
    {Your package. Case of this library<package_own-(version)>}/src/main.rs"

No runtime deps