From b0796c18f38e22b58810a6487ac65a6eda41f107 Mon Sep 17 00:00:00 2001 From: Martin Algesten Date: Thu, 29 Sep 2022 17:29:32 +0200 Subject: [PATCH] Make build work (#546) The mbedtls example has caused problem in the main build a number of times. By making it a standalone `cargo new --bin`, we can keep it in the source tree as a good example but avoid having it break the main build. Also, fix some clippy lints. --- Cargo.toml | 1 - examples/mbedtls/Cargo.toml | 8 ++++++++ examples/mbedtls/README.md | 9 +++++++++ examples/mbedtls/{ => src}/main.rs | 0 examples/mbedtls/{ => src}/mbedtls_connector.rs | 0 examples/smoke-test/main.rs | 7 +++---- src/error.rs | 2 +- src/header.rs | 2 +- src/response.rs | 4 ++-- src/stream.rs | 2 +- src/test/agent_test.rs | 2 +- src/test/mod.rs | 1 + 12 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 examples/mbedtls/Cargo.toml create mode 100644 examples/mbedtls/README.md rename examples/mbedtls/{ => src}/main.rs (100%) rename examples/mbedtls/{ => src}/mbedtls_connector.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index f7ab24e..0b01876 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,7 +50,6 @@ serde = { version = "1", features = ["derive"] } env_logger = "0.9" rustls = { version = "0.20", features = ["dangerous_configuration"] } rustls-pemfile = { version = "1.0" } -mbedtls = { version = "0.8.1" } [[example]] name = "cureq" diff --git a/examples/mbedtls/Cargo.toml b/examples/mbedtls/Cargo.toml new file mode 100644 index 0000000..51abba1 --- /dev/null +++ b/examples/mbedtls/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "mbedtls-example" +version = "0.0.1" +edition = "2021" + + +[dependencies] +mbedtls = { version = "0.8.1" } diff --git a/examples/mbedtls/README.md b/examples/mbedtls/README.md new file mode 100644 index 0000000..0e493c0 --- /dev/null +++ b/examples/mbedtls/README.md @@ -0,0 +1,9 @@ +mbedtls-example +=============== + +To run this example you need to `cd` into the directory and use `cargo run`. + +``` +cd ureq/exampled/mbedtls +cargo run +``` diff --git a/examples/mbedtls/main.rs b/examples/mbedtls/src/main.rs similarity index 100% rename from examples/mbedtls/main.rs rename to examples/mbedtls/src/main.rs diff --git a/examples/mbedtls/mbedtls_connector.rs b/examples/mbedtls/src/mbedtls_connector.rs similarity index 100% rename from examples/mbedtls/mbedtls_connector.rs rename to examples/mbedtls/src/mbedtls_connector.rs diff --git a/examples/smoke-test/main.rs b/examples/smoke-test/main.rs index 4c7ea28..b19a79f 100644 --- a/examples/smoke-test/main.rs +++ b/examples/smoke-test/main.rs @@ -5,7 +5,6 @@ use std::time::Duration; use std::{env, error, fmt, result}; use log::{error, info}; -use ureq; #[derive(Debug)] struct Oops(String); @@ -77,7 +76,7 @@ fn get_many(urls: Vec, simultaneous_fetches: usize) -> Result<()> { } fn main() -> Result<()> { - let args = env::args(); + let mut args = env::args(); if args.len() == 1 { println!( r##"Usage: {:#?} top-1m.csv @@ -94,11 +93,11 @@ using 50 threads concurrently. return Ok(()); } env_logger::init(); - let file = std::fs::File::open(args.skip(1).next().unwrap())?; + let file = std::fs::File::open(args.nth(1).unwrap())?; let bufreader = BufReader::new(file); let mut urls = vec![]; for line in bufreader.lines() { - let domain = line?.rsplit(",").next().unwrap().to_string(); + let domain = line?.rsplit(',').next().unwrap().to_string(); urls.push(format!("http://{}/", domain)); urls.push(format!("https://{}/", domain)); urls.push(format!("http://www.{}/", domain)); diff --git a/src/error.rs b/src/error.rs index 3fec78b..9610fc7 100644 --- a/src/error.rs +++ b/src/error.rs @@ -328,7 +328,7 @@ impl Error { } /// One of the types of error the can occur when processing a Request. -#[derive(Debug, PartialEq, Clone, Copy)] +#[derive(Debug, PartialEq, Eq, Clone, Copy)] pub enum ErrorKind { /// The url could not be understood. InvalidUrl, diff --git a/src/header.rs b/src/header.rs index db9d62e..ff8005e 100644 --- a/src/header.rs +++ b/src/header.rs @@ -62,7 +62,7 @@ impl fmt::Display for HeaderLine { } } -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] /// Wrapper type for a header field. /// pub struct Header { diff --git a/src/response.rs b/src/response.rs index 984bc5b..65a81af 100644 --- a/src/response.rs +++ b/src/response.rs @@ -799,9 +799,9 @@ pub(crate) fn charset_from_content_type(header: Option<&str>) -> &str { header .and_then(|header| { header.find(';').and_then(|semi| { - (&header[semi + 1..]) + header[semi + 1..] .find('=') - .map(|equal| (&header[semi + equal + 2..]).trim()) + .map(|equal| header[semi + equal + 2..].trim()) }) }) .unwrap_or(DEFAULT_CHARACTER_SET) diff --git a/src/stream.rs b/src/stream.rs index 6497511..cefe48b 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -666,7 +666,7 @@ mod tests { let mut deadline_stream = DeadlineStream::new(stream, None); let mut buf = [0u8; 1]; for _ in 0..8193 { - deadline_stream.read(&mut buf).unwrap(); + let _ = deadline_stream.read(&mut buf).unwrap(); } let reads = reads.lock().unwrap(); assert_eq!(reads.len(), 2); diff --git a/src/test/agent_test.rs b/src/test/agent_test.rs index b7d254c..ea0abda 100644 --- a/src/test/agent_test.rs +++ b/src/test/agent_test.rs @@ -80,7 +80,7 @@ fn connection_reuse_with_408() { // pulls from the pool. If for some reason the timed-out // connection wasn't in the pool, we won't be testing what // we thought we were testing. - let resp = agent.post(&url).send_string("hello".into()).unwrap(); + let resp = agent.post(&url).send_string("hello").unwrap(); assert_eq!(resp.status(), 200); } diff --git a/src/test/mod.rs b/src/test/mod.rs index 2e27e5c..349271a 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -20,6 +20,7 @@ mod timeout; type RequestHandler = dyn Fn(&Unit) -> Result + Send + 'static; +#[allow(clippy::type_complexity)] pub(crate) static TEST_HANDLERS: Lazy>>>> = Lazy::new(|| Arc::new(Mutex::new(HashMap::new())));