utkarshkukreti / select.rs

A Rust library to extract useful data from HTML documents, suitable for web scraping.
MIT License
971 stars 69 forks source link

Can't build sample code #7

Closed mre closed 8 years ago

mre commented 8 years ago

Hi,

so I'm pretty sure the error is on my side but I can't find it. Sorry for the noob question :smile:. I can't compile the following code:

extern crate select;
use select::document::Document;

fn main() {
     let document = Document::from("test");
}

When running cargo build i get the following output:

Compiling test v0.1.0 (file:///Volumes/Data/Code/snippets/rust/test)
src/main.rs:5:36: 5:42 error: mismatched types:
 expected `select::document::Document`,
    found `&'static str`
(expected struct `select::document::Document`,
    found &-ptr) [E0308]
src/main.rs:5      let document = Document::from("test");
                                                 ^~~~~~
src/main.rs:5:36: 5:42 help: run `rustc --explain E0308` to see a detailed explanation

For some reason it requires a select::document::Document but looking at the test code, it should also handle an &str type: https://github.com/utkarshkukreti/select.rs/blob/master/tests/document_tests.rs#L13 What am I missing here?

utkarshkukreti commented 8 years ago

You're probably using version 0.2.x of select, while the From<&str> impl for Document was added for the upcoming 0.3.x version. You should either use Document::from_str(str) or depend on the git version of select by adding the following to your Cargo.toml:

[dependencies]
select = { git = "https://github.com/utkarshkukreti/select.rs" }
mre commented 8 years ago

Perfect. It works like a charm! I decided to check out the newest version and go with the git repository. Thanks for your help.