Small Rust scripts
1#!/usr/bin/env -S cargo +nightly -Zscript
2
3---
4[package]
5edition = "2024"
6[dependencies]
7reqwest = { version = "0.11.3", features = ["blocking"] }
8---
9
10use reqwest::blocking::Client;
11
12fn main() {
13 let client = Client::new();
14 let res = client
15 .get("https://ipecho.net/plain")
16 .send()
17 .expect("unexpected error while trying to reach ipecho.net");
18
19 if res.status() != 200 {
20 panic!("Unexpected status code {}", res.status());
21 }
22
23 let ip = res.text().expect("should be able to deserialize body");
24 println!("{}", ip);
25}