diff --git a/examples/mbedtls/main.rs b/examples/mbedtls/main.rs index dff3d45..5d73586 100644 --- a/examples/mbedtls/main.rs +++ b/examples/mbedtls/main.rs @@ -1,39 +1,12 @@ -use std::io::{self, Read}; +use std::io::Read; use std::sync::Arc; use std::time::Duration; -use std::{env, error, fmt, result}; -pub mod mbedtls_connector; +mod mbedtls_connector; -use log::{error, info}; use ureq; -#[derive(Debug)] -struct Oops(String); - -impl From for Oops { - fn from(e: io::Error) -> Oops { - Oops(e.to_string()) - } -} - -impl From for Oops { - fn from(e: ureq::Error) -> Oops { - Oops(e.to_string()) - } -} - -impl error::Error for Oops {} - -impl fmt::Display for Oops { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.0.fmt(f) - } -} - -type Result = result::Result; - -fn get(agent: &ureq::Agent, url: &str) -> Result> { +fn get(agent: &ureq::Agent, url: &str) -> Result, ureq::Error> { let response = agent.get(url).call()?; let mut reader = response.into_reader(); let mut bytes = vec![]; @@ -42,17 +15,14 @@ fn get(agent: &ureq::Agent, url: &str) -> Result> { } fn get_and_write(agent: &ureq::Agent, url: &str) { - info!("🕷️ {}", url); + println!("🕷️ {}", url); match get(agent, url) { - Ok(_) => info!("Good: ✔️ {}\n", url), - Err(e) => error!("Bad: ⚠️ {} {}\n", url, e), + Ok(_) => println!("Good: ✔️ {}\n", url), + Err(e) => println!("Bad: ⚠️ {} {}\n", url, e), } } -fn main() -> Result<()> { - let _args = env::args(); - env_logger::init(); - +fn main() -> Result<(), ureq::Error> { let agent = ureq::builder() .tls_connector(Arc::new(mbedtls_connector::MbedTlsConnector::new( mbedtls::ssl::config::AuthMode::None, @@ -61,7 +31,7 @@ fn main() -> Result<()> { .timeout(Duration::from_secs(20)) .build(); - get_and_write(&agent, "https://example.com/"); + get_and_write(&agent, "https://httpbin.org/get"); Ok(()) }