Browse Source

04-linkedlist

master
Akshay Dixit 4 years ago
parent
commit
9336b98f5e
  1. 1
      Cargo.toml
  2. 36
      src/bin/04-linkedlist.rs

1
Cargo.toml

@ -6,3 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
reqwest = {version = "0.11.10", features = ["blocking"]}

36
src/bin/04-linkedlist.rs

@ -0,0 +1,36 @@
use std::collections::HashSet;
const REQUEST_URL: &str = "http://www.pythonchallenge.com/pc/def/linkedlist.php";
fn get_next_nothing(current_nothing: String) -> Result<String, reqwest::Error>
{
let client = reqwest::blocking::Client::new();
let resp = client.get(REQUEST_URL)
.query(&[("nothing", current_nothing)])
.send()?;
let body = resp.text()?;
let nothing = body.split_ascii_whitespace().last().unwrap();
Ok(nothing.to_string())
}
fn main() -> Result<(), reqwest::Error> {
let mut nothings= HashSet::new();
let mut current_nothing = String::from("12345");
while !nothings.contains(&current_nothing)
{
nothings.insert(current_nothing.clone());
current_nothing = get_next_nothing(current_nothing)?;
println!("Next nothing is: {}",current_nothing);
}
println!("{:?}", nothings);
Ok(())
}
Loading…
Cancel
Save