Skip to content

feat: inline format args #270

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

Merged
merged 2 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions examples/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn main() {
// Exchange the code with a token.
let token_res = client.exchange_code(code).request(&http_client);

println!("Github returned the following token:\n{:?}\n", token_res);
println!("Github returned the following token:\n{token_res:?}\n");

if let Ok(token) = token_res {
// NB: Github returns a single comma-separated "scope" parameter instead of multiple
Expand All @@ -130,6 +130,6 @@ fn main() {
} else {
Vec::new()
};
println!("Github returned the following scopes:\n{:?}\n", scopes);
println!("Github returned the following scopes:\n{scopes:?}\n");
}
}
4 changes: 2 additions & 2 deletions examples/github_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async fn main() {
// Exchange the code with a token.
let token_res = client.exchange_code(code).request_async(&http_client).await;

println!("Github returned the following token:\n{:?}\n", token_res);
println!("Github returned the following token:\n{token_res:?}\n");

if let Ok(token) = token_res {
// NB: Github returns a single comma-separated "scope" parameter instead of multiple
Expand All @@ -131,6 +131,6 @@ async fn main() {
} else {
Vec::new()
};
println!("Github returned the following scopes:\n{:?}\n", scopes);
println!("Github returned the following scopes:\n{scopes:?}\n");
}
}
5 changes: 1 addition & 4 deletions examples/google.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ fn main() {
.set_pkce_verifier(pkce_code_verifier)
.request(&http_client);

println!(
"Google returned the following token:\n{:?}\n",
token_response
);
println!("Google returned the following token:\n{token_response:?}\n");

// Revoke the obtained token
let token_response = token_response.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/google_devicecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ fn main() {
.request(&http_client, std::thread::sleep, None)
.expect("Failed to get token");

println!("Google returned the following token:\n{:?}\n", token);
println!("Google returned the following token:\n{token:?}\n");
}
2 changes: 1 addition & 1 deletion examples/letterboxd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn main() -> Result<(), anyhow::Error> {
.exchange_password(&letterboxd_username, &letterboxd_password)
.request(&|request| http_client.execute(request))?;

println!("{:?}", token_result);
println!("{token_result:?}");

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/microsoft_devicecode_common_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
.request_async(&http_client, tokio::time::sleep, None)
.await;

eprintln!("Token:{:?}", token_result);
eprintln!("Token:{token_result:?}");

Ok(())
}
2 changes: 1 addition & 1 deletion examples/microsoft_devicecode_tenant_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
.request_async(&http_client, tokio::time::sleep, None)
.await;

eprintln!("Token:{:?}", token_result);
eprintln!("Token:{token_result:?}");

Ok(())
}
2 changes: 1 addition & 1 deletion examples/msgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,5 @@ fn main() {
.set_pkce_verifier(pkce_code_verifier)
.request(&http_client);

println!("MS Graph returned the following token:\n{:?}\n", token);
println!("MS Graph returned the following token:\n{token:?}\n");
}
5 changes: 1 addition & 4 deletions examples/wunderlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,5 @@ fn main() {
.add_extra_param("client_secret", client_secret_str)
.request(&http_client);

println!(
"Wunderlist returned the following token:\n{:?}\n",
token_res
);
println!("Wunderlist returned the following token:\n{token_res:?}\n");
}
8 changes: 3 additions & 5 deletions src/devicecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,7 @@ where
let timeout_dur = timeout.unwrap_or_else(|| self.dev_auth_resp.expires_in());
let chrono_timeout = chrono::Duration::from_std(timeout_dur).map_err(|e| {
RequestTokenError::Other(format!(
"failed to convert `{:?}` to `chrono::Duration`: {}",
timeout_dur, e
"failed to convert `{timeout_dur:?}` to `chrono::Duration`: {e}"
))
})?;

Expand Down Expand Up @@ -694,10 +693,9 @@ mod tests {
\"verification_uri\": \"https://verify/here\", \
\"user_code\": \"abcde\", \
\"verification_uri_complete\": \"https://verify/here?abcde\", \
\"expires_in\": {}, \
\"expires_in\": {expires_in}, \
\"interval\": 1 \
}}",
expires_in
}}"
);

let device_auth_url =
Expand Down
4 changes: 1 addition & 3 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ where
Err(
RequestTokenError::Other(
format!(
"unexpected response Content-Type: {:?}, should be `{}`",
content_type,
CONTENT_TYPE_JSON
"unexpected response Content-Type: {content_type:?}, should be `{CONTENT_TYPE_JSON}`",
)
)
)
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ where
formatted.push(')');
}

write!(f, "{}", formatted)
write!(f, "{formatted}")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub(crate) mod colorful_extension {
fn fmt(&self, f: &mut Formatter) -> Result<(), FormatterError> {
let message: &str = self.to_str();

write!(f, "{}", message)
write!(f, "{message}")
}
}

Expand Down
24 changes: 12 additions & 12 deletions src/token/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,12 @@ fn test_exchange_code_with_simple_json_error() {
assert_eq!(
"StandardErrorResponse { error: invalid_request, \
error_description: Some(\"stuff happened\"), error_uri: None }",
format!("{:?}", error_response)
format!("{error_response:?}")
);
// Test Display trait for ErrorResponse
assert_eq!(
"invalid_request: stuff happened",
format!("{}", error_response)
format!("{error_response}")
);

// Test Debug trait for BasicErrorResponseType
Expand All @@ -732,14 +732,14 @@ fn test_exchange_code_with_simple_json_error() {
serde_json::from_str::<BasicErrorResponse>(&serialized_json).unwrap();
assert_eq!(error_response, &deserialized_error);
}
other => panic!("Unexpected error: {:?}", other),
other => panic!("Unexpected error: {other:?}"),
}

// Test Debug trait for RequestTokenError
assert_eq!(
"ServerResponse(StandardErrorResponse { error: invalid_request, \
error_description: Some(\"stuff happened\"), error_uri: None })",
format!("{:?}", token_err)
format!("{token_err:?}")
);
// Test Display trait for RequestTokenError
assert_eq!(
Expand Down Expand Up @@ -783,7 +783,7 @@ fn test_exchange_code_with_json_parse_error() {
json_err.inner().classify()
);
}
other => panic!("Unexpected error: {:?}", other),
other => panic!("Unexpected error: {other:?}"),
}
}

Expand Down Expand Up @@ -816,7 +816,7 @@ fn test_exchange_code_with_unexpected_content_type() {
error_str
);
}
other => panic!("Unexpected error: {:?}", other),
other => panic!("Unexpected error: {other:?}"),
}
}

Expand Down Expand Up @@ -860,7 +860,7 @@ fn test_exchange_code_with_invalid_token_type() {
json_err.inner().classify()
);
}
other => panic!("Unexpected error: {:?}", other),
other => panic!("Unexpected error: {other:?}"),
}
}

Expand Down Expand Up @@ -902,7 +902,7 @@ fn test_exchange_code_with_400_status_code() {
);
assert_eq!(None, error_response.error_uri());
}
other => panic!("Unexpected error: {:?}", other),
other => panic!("Unexpected error: {other:?}"),
}

assert_eq!(
Expand All @@ -926,7 +926,7 @@ fn test_exchange_code_fails_gracefully_on_transport_error() {

match token.err().unwrap() {
RequestTokenError::Request(FakeError::Err) => (),
other => panic!("Unexpected error: {:?}", other),
other => panic!("Unexpected error: {other:?}"),
}
}

Expand Down Expand Up @@ -1111,14 +1111,14 @@ fn test_extension_with_simple_json_error() {
.unwrap();
assert_eq!(error_response, &deserialized_error);
}
other => panic!("Unexpected error: {:?}", other),
other => panic!("Unexpected error: {other:?}"),
}

// Test Debug trait for RequestTokenError
assert_eq!(
"ServerResponse(StandardErrorResponse { error: too_light, \
error_description: Some(\"stuff happened\"), error_uri: Some(\"https://errors\") })",
format!("{:?}", token_err)
format!("{token_err:?}")
);
// Test Display trait for RequestTokenError
assert_eq!(
Expand Down Expand Up @@ -1210,7 +1210,7 @@ fn test_extension_with_custom_json_error() {
RequestTokenError::ServerResponse(e) => {
assert_eq!("non-compliant oauth implementation ;-)", e.custom_error)
}
e => panic!("failed to correctly parse custom server error, got {:?}", e),
e => panic!("failed to correctly parse custom server error, got {e:?}"),
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ mod tests {
#[test]
fn test_secret_redaction() {
let secret = ClientSecret::new("top_secret".to_string());
assert_eq!("ClientSecret([redacted])", format!("{:?}", secret));
assert_eq!("ClientSecret([redacted])", format!("{secret:?}"));
}

#[test]
Expand Down
Loading