Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve generic type parameters #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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