Skip to content

Commit

Permalink
Fix recent clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sagebind committed Jan 10, 2022
1 parent 37cdccd commit 8872f19
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static USER_AGENT: Lazy<String> = Lazy::new(|| {
/// .build()?;
/// # Ok::<(), isahc::Error>(())
/// ```
#[must_use = "builders have no effect if unused"]
pub struct HttpClientBuilder {
agent_builder: AgentBuilder,
client_config: ClientConfig,
Expand Down
1 change: 1 addition & 0 deletions src/config/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl ResolveMap {
}

/// Add a DNS mapping for a given host and port pair.
#[must_use = "builders have no effect if unused"]
pub fn add<H, A>(mut self, host: H, port: u16, addr: A) -> Self
where
H: AsRef<str>,
Expand Down
28 changes: 28 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub trait Configurable: request::WithRequestConfig {
/// .expect_err("page should time out");
/// # Ok::<(), isahc::Error>(())
/// ```
#[must_use = "builders have no effect if unused"]
fn timeout(self, timeout: Duration) -> Self {
self.with_config(move |config| {
config.timeout = Some(timeout);
Expand All @@ -83,6 +84,7 @@ pub trait Configurable: request::WithRequestConfig {
/// Set a timeout for establishing connections to a host.
///
/// If not set, a default connect timeout of 300 seconds will be used.
#[must_use = "builders have no effect if unused"]
fn connect_timeout(self, timeout: Duration) -> Self {
self.with_config(move |config| {
config.connect_timeout = Some(timeout);
Expand All @@ -93,6 +95,7 @@ pub trait Configurable: request::WithRequestConfig {
/// a minimum speed limit. `low_speed` is that limit in bytes/s.
///
/// If not set, no low speed limits are imposed.
#[must_use = "builders have no effect if unused"]
fn low_speed_timeout(self, low_speed: u32, timeout: Duration) -> Self {
self.with_config(move |config| {
config.low_speed_timeout = Some((low_speed, timeout));
Expand Down Expand Up @@ -124,6 +127,7 @@ pub trait Configurable: request::WithRequestConfig {
/// .build()?;
/// # Ok::<(), isahc::Error>(())
/// ```
#[must_use = "builders have no effect if unused"]
fn version_negotiation(self, negotiation: VersionNegotiation) -> Self {
self.with_config(move |config| {
config.version_negotiation = Some(negotiation);
Expand Down Expand Up @@ -153,13 +157,15 @@ pub trait Configurable: request::WithRequestConfig {
/// .expect_err("too many redirects");
/// # Ok::<(), isahc::Error>(())
/// ```
#[must_use = "builders have no effect if unused"]
fn redirect_policy(self, policy: RedirectPolicy) -> Self {
self.with_config(move |config| {
config.redirect_policy = Some(policy);
})
}

/// Update the `Referer` header automatically when following redirects.
#[must_use = "builders have no effect if unused"]
fn auto_referer(self) -> Self {
self.with_config(move |config| {
config.auto_referer = Some(true);
Expand All @@ -177,6 +183,7 @@ pub trait Configurable: request::WithRequestConfig {
/// This method is only available when the [`cookies`](index.html#cookies)
/// feature is enabled.
#[cfg(feature = "cookies")]
#[must_use = "builders have no effect if unused"]
fn cookie_jar(self, cookie_jar: crate::cookies::CookieJar) -> Self;

/// Enable or disable automatic decompression of the response body for
Expand All @@ -194,6 +201,7 @@ pub trait Configurable: request::WithRequestConfig {
/// If you do not specify a specific value for the
/// [`Accept-Encoding`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding)
/// header, Isahc will set one for you automatically based on this option.
#[must_use = "builders have no effect if unused"]
fn automatic_decompression(self, decompress: bool) -> Self {
self.with_config(move |config| {
config.automatic_decompression = Some(decompress);
Expand Down Expand Up @@ -258,6 +266,7 @@ pub trait Configurable: request::WithRequestConfig {
/// .build()?;
/// # Ok::<(), isahc::Error>(())
/// ```
#[must_use = "builders have no effect if unused"]
fn expect_continue<T>(self, expect: T) -> Self
where
T: Into<ExpectContinue>,
Expand Down Expand Up @@ -289,6 +298,7 @@ pub trait Configurable: request::WithRequestConfig {
/// .build()?;
/// # Ok::<(), isahc::Error>(())
/// ```
#[must_use = "builders have no effect if unused"]
fn authentication(self, authentication: Authentication) -> Self {
self.with_config(move |config| {
config.authentication = Some(authentication);
Expand All @@ -299,20 +309,23 @@ pub trait Configurable: request::WithRequestConfig {
///
/// This setting will do nothing unless you also set one or more
/// authentication methods using [`Configurable::authentication`].
#[must_use = "builders have no effect if unused"]
fn credentials(self, credentials: Credentials) -> Self {
self.with_config(move |config| {
config.credentials = Some(credentials);
})
}

/// Enable TCP keepalive with a given probe interval.
#[must_use = "builders have no effect if unused"]
fn tcp_keepalive(self, interval: Duration) -> Self {
self.with_config(move |config| {
config.tcp_keepalive = Some(interval);
})
}

/// Enables the `TCP_NODELAY` option on connect.
#[must_use = "builders have no effect if unused"]
fn tcp_nodelay(self) -> Self {
self.with_config(move |config| {
config.tcp_nodelay = Some(true);
Expand Down Expand Up @@ -352,6 +365,7 @@ pub trait Configurable: request::WithRequestConfig {
/// .body(())?;
/// # Ok::<(), isahc::Error>(())
/// ```
#[must_use = "builders have no effect if unused"]
fn interface<I>(self, interface: I) -> Self
where
I: Into<NetworkInterface>,
Expand All @@ -368,6 +382,7 @@ pub trait Configurable: request::WithRequestConfig {
/// This does not affect requests with an explicit IP address as the host.
///
/// The default is [`IpVersion::Any`].
#[must_use = "builders have no effect if unused"]
fn ip_version(self, version: IpVersion) -> Self {
self.with_config(move |config| {
config.ip_version = Some(version);
Expand Down Expand Up @@ -412,6 +427,7 @@ pub trait Configurable: request::WithRequestConfig {
/// .body(())?;
/// # Ok::<(), isahc::Error>(())
/// ```
#[must_use = "builders have no effect if unused"]
fn dial<D>(self, dialer: D) -> Self
where
D: Into<Dialer>,
Expand Down Expand Up @@ -461,6 +477,7 @@ pub trait Configurable: request::WithRequestConfig {
/// .build()?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
#[must_use = "builders have no effect if unused"]
fn proxy(self, proxy: impl Into<Option<http::Uri>>) -> Self {
self.with_config(move |config| {
config.proxy = Some(proxy.into());
Expand All @@ -480,6 +497,7 @@ pub trait Configurable: request::WithRequestConfig {
/// .build()?;
/// # Ok::<(), isahc::Error>(())
/// ```
#[must_use = "builders have no effect if unused"]
fn proxy_blacklist<I, T>(self, hosts: I) -> Self
where
I: IntoIterator<Item = T>,
Expand Down Expand Up @@ -513,6 +531,7 @@ pub trait Configurable: request::WithRequestConfig {
/// .build()?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
#[must_use = "builders have no effect if unused"]
fn proxy_authentication(self, authentication: Authentication) -> Self {
self.with_config(move |config| {
config.proxy_authentication = Some(Proxy(authentication));
Expand All @@ -524,6 +543,7 @@ pub trait Configurable: request::WithRequestConfig {
/// This setting will do nothing unless you also set one or more proxy
/// authentication methods using
/// [`Configurable::proxy_authentication`].
#[must_use = "builders have no effect if unused"]
fn proxy_credentials(self, credentials: Credentials) -> Self {
self.with_config(move |config| {
config.proxy_credentials = Some(Proxy(credentials));
Expand All @@ -533,6 +553,7 @@ pub trait Configurable: request::WithRequestConfig {
/// Set a maximum upload speed for the request body, in bytes per second.
///
/// The default is unlimited.
#[must_use = "builders have no effect if unused"]
fn max_upload_speed(self, max: u64) -> Self {
self.with_config(move |config| {
config.max_upload_speed = Some(max);
Expand All @@ -542,6 +563,7 @@ pub trait Configurable: request::WithRequestConfig {
/// Set a maximum download speed for the response body, in bytes per second.
///
/// The default is unlimited.
#[must_use = "builders have no effect if unused"]
fn max_download_speed(self, max: u64) -> Self {
self.with_config(move |config| {
config.max_download_speed = Some(max);
Expand Down Expand Up @@ -590,6 +612,7 @@ pub trait Configurable: request::WithRequestConfig {
/// .build()?;
/// # Ok::<(), isahc::Error>(())
/// ```
#[must_use = "builders have no effect if unused"]
fn ssl_client_certificate(self, certificate: ClientCertificate) -> Self {
self.with_config(move |config| {
config.ssl_client_certificate = Some(certificate);
Expand Down Expand Up @@ -617,6 +640,7 @@ pub trait Configurable: request::WithRequestConfig {
/// .build()?;
/// # Ok::<(), isahc::Error>(())
/// ```
#[must_use = "builders have no effect if unused"]
fn ssl_ca_certificate(self, certificate: CaCertificate) -> Self {
self.with_config(move |config| {
config.ssl_ca_certificate = Some(certificate);
Expand All @@ -630,6 +654,7 @@ pub trait Configurable: request::WithRequestConfig {
/// at <https://curl.haxx.se/docs/ssl-ciphers.html>.
///
/// The default is unset and will result in the system defaults being used.
#[must_use = "builders have no effect if unused"]
fn ssl_ciphers<I, T>(self, ciphers: I) -> Self
where
I: IntoIterator<Item = T>,
Expand Down Expand Up @@ -674,6 +699,7 @@ pub trait Configurable: request::WithRequestConfig {
/// .build()?;
/// # Ok::<(), isahc::Error>(())
/// ```
#[must_use = "builders have no effect if unused"]
fn ssl_options(self, options: SslOption) -> Self {
self.with_config(move |config| {
config.ssl_options = Some(options);
Expand All @@ -690,6 +716,7 @@ pub trait Configurable: request::WithRequestConfig {
///
/// This option has no effect when using HTTP/2 or newer where headers are
/// required to be lowercase.
#[must_use = "builders have no effect if unused"]
fn title_case_headers(self, enable: bool) -> Self {
self.with_config(move |config| {
config.title_case_headers = Some(enable);
Expand All @@ -711,6 +738,7 @@ pub trait Configurable: request::WithRequestConfig {
/// Disabling metrics may be necessary for absolute peak performance.
///
/// By default metrics are disabled.
#[must_use = "builders have no effect if unused"]
fn metrics(self, enable: bool) -> Self {
self.with_config(move |config| {
config.enable_metrics = Some(enable);
Expand Down
1 change: 1 addition & 0 deletions src/cookies/cookie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl Error for ParseError {}
/// .unwrap();
/// ```
#[derive(Clone, Debug)]
#[must_use = "builders have no effect if unused"]
pub struct CookieBuilder {
/// The name of the cookie.
name: String,
Expand Down
1 change: 1 addition & 0 deletions src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub trait ResponseExt<T> {
}

impl<T> ResponseExt<T> for Response<T> {
#[allow(clippy::redundant_closure)]
fn trailer(&self) -> &Trailer {
// Return a static empty trailer if the extension does not exist. This
// offers a more convenient API so that users do not have to unwrap the
Expand Down

0 comments on commit 8872f19

Please sign in to comment.