Skip to content

Commit

Permalink
Use AsRef<str> instead of Into<URL>
Browse files Browse the repository at this point in the history
Saves allocations and/or taking ownership
Potentially a breaking change on some really weird types
  • Loading branch information
alpha-tango-kilo committed Mar 21, 2023
1 parent bfab6b2 commit 140a982
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,14 @@ impl Request {
/// key or value.
///
/// If `urlencoding` is enabled, the key and value are both encoded.
pub fn with_param<T: Into<String>, U: Into<String>>(mut self, key: T, value: U) -> Request {
let key = key.into();
#[cfg_attr(not(urlencoding), allow(clippy::needless_borrow))]
pub fn with_param<T: AsRef<str>, U: AsRef<str>>(mut self, key: T, value: U) -> Request {
let key = key.as_ref();
#[cfg(feature = "urlencoding")]
let key = urlencoding::encode(&key);
let value = value.into();
let key = urlencoding::encode(key);
let value = value.as_ref();
#[cfg(feature = "urlencoding")]
let value = urlencoding::encode(&value);
let value = urlencoding::encode(value);

if !self.params.is_empty() {
self.params.push('&');
Expand Down Expand Up @@ -451,13 +452,14 @@ impl ParsedRequest {
}
}

fn parse_url(url: &str) -> Result<(bool, URL, Port, URL), Error> {
fn parse_url(url: impl AsRef<str>) -> Result<(bool, URL, Port, URL), Error> {
enum UrlParseStatus {
Host,
Port,
Resource,
}

let url = url.as_ref();
let (url, https) = if let Some(after_protocol) = url.strip_prefix("http://") {
(after_protocol, false)
} else if let Some(after_protocol) = url.strip_prefix("https://") {
Expand Down

0 comments on commit 140a982

Please sign in to comment.