Why exampels from GitHub do not work?

Almost all ... How to study Rust in such situation ? What is going in Crates.io ?

For instance

reqwest = "*"
select = "*"
scraper = "*"
prettytable-rs = "*"
extern crate reqwest;
extern crate select;

use select::document::Document;
use select::predicate::Name;

fn main() {

fn hacker_news(url: &str) {
    let mut resp = reqwest::get(url).unwrap();

        .filter_map(|n| n.attr("href"))
        .for_each(|x| println!("{}", x));

This code is fresh and working fine.. It has been posted 1 day ago

reqwest     =     "0.11"  
tokio       =   {  version =   "1" ,   features    =   [   "full"  ]  } 
#   [   tokio   ::  main    ]
  pub async  fn main (   )  -> Result   <  (    )   ,   reqwest ::  Error    >  {
    let  my_htm    =   reqwest ::   Client  ::  new (   )
    .get   ( "http://checkip.dyndns.com" )
    .send   (  )
    .await  ?
    .text   (   )
    .await  ? ;

    println !   (   "Current IP Address:   {:#?}  "  , my_htm   ) ;

    Ok    (   (   ) )  

It is not clear at all what you are asking. You only state that "this code is fresh and working fine", but this contradicts:

  • your claim that it doesn't work, and
  • the fact that the linked blog post is not "fresh", it is 4 years old (it is from 2018).

Furthermore, you don't describe what exactly the problem is. There are many ways in which a program can fail. Tell us what is or isn't happening. "It doesn't work" won't help us find a solution.


I copy simple codes from GitHub and try compile its and face wrong crates in Crates.io problems.. Almost always.. Is it normal?
First quote is an example of such kind of problem.
Second code is also from GitHub, and it works. Maybe the reason is it is fresh posted . (1 day ago) There is not link to it. I thought it is not necessary

I just study rust, am not searching a solution for my project. My question is what is the best strategy in practicing rust code writing..

It looks like the latest version of the reqwest crate was 0.8.2 when the blog post was created. The current version is 0.11.10; between these versions, reqwest::get() was renamed to reqwest::blocking::get() and placed behind the blocking feature flag. It's generally considered a good idea for authors to specify the dependency versions used, so that users can reproduce their programs later. In this case, the code compiles by setting reqwest = "0.9.0" in Cargo.toml.


...and that's why we should never specify dependency version as = "*", especially for tutorials/examples, though it seems quick and easy way at the time the post is written. It actually harm beginners as our echosystem grow faster.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.