How to resolve ambiguous associated type with NetRc

Viewed 38

I'm trying to make curl-rust optionally make use of a ~/.netrc file, but I cannot make it compile:

use curl::easy::Easy;

fn main() -> Result<(), Box<dyn std::error::Error>> {

    let urlstring = "https://example.com/";
    let mut easy = Easy::new();

    // Setting some curl options
    easy.url(urlstring)?;
    easy.fail_on_error(true)?;
    easy.netrc(Easy::NetRc::Optional)?;

    // Main activity goes here

    Ok(())
}

When building, I keep getting the following error:

error[E0223]: ambiguous associated type
  --> src/main.rs:11:16
   |
11 |     easy.netrc(Easy::NetRc::Optional)?;
   |                ^^^^^^^^^^^ help: use fully-qualified syntax: `<Easy as Trait>::NetRc`

For more information about this error, try `rustc --explain E0223`.

What am I doing wrong?

1 Answers

In this case the error seems misleading.

From the documentation, NetRc emun lives under the curl::easy module, not part of the Easy struct. Just bring it to scope as you did with Easy itself:

use curl::easy::{Easy, NetRc};

fn main() -> Result<(), Box<dyn std::error::Error>> {

    let urlstring = "https://example.com/";
    let mut easy = Easy::new();

    // Setting some curl options
    easy.url(urlstring)?;
    easy.fail_on_error(true)?;
    easy.netrc(NetRc::Optional)?;

    // Main activity goes here

    Ok(())
}

Or use the full path:

easy.netrc(curl::easy::NetRc::Optional)?;
Related