Search code examples
rustrust-cratestoml

Import rust package with alias in toml


I'm trying to make a simple program checking execution times on two different branches of the same rust project.

I wanted to have my .toml look something like this

[dependencies]
cron_original = { git = "https://github.com/zslayton/cron" }
cron_fork = { git = "https://github.com/koenichiwa/cron", branch = "feature/reimplement-queries"}

And my program look something like this:

fn main() {
    let expression = String::from("0-59 * 0-23 ?/2 1,2-4 ? *");
    let schedule_orig = cron_original::Schedule::from_str(expression);
    let schedule_fork = cron_fork::Schedule::from_str(expression);
    // Check difference in execution times on these structs
}

but I'm getting no matching package named 'cron_fork' found. Is there anyway to import a package with a specific alias? I was thinking about creating something that would automate checks like this.


Solution

  • You need to specify package keys for those dependencies so cargo knows that you really want those packages even though you specify a different name:

    [dependencies]
    cron_original = { git = "https://github.com/zslayton/cron", package="cron" }
    cron_fork = { git = "https://github.com/koenichiwa/cron", branch = "feature/reimplement-queries", package="cron" }
    

    See the Renaming dependencies in Cargo.toml section in Specifying Dependencies documentation for details.