From 470a742b34762a793aefbfdf1e2885d5b137b9f7 Mon Sep 17 00:00:00 2001 From: Tristan Miller Date: Mon, 11 Sep 2023 21:37:54 -0600 Subject: [PATCH] More changes due to new clippy warning uninlined-format-args --- did-ethr/src/lib.rs | 6 +++--- did-ion/src/sidetree.rs | 8 ++++---- did-key/src/lib.rs | 2 +- did-onion/src/lib.rs | 13 +++++------- did-pkh/src/lib.rs | 4 ++-- did-sol/src/lib.rs | 2 +- did-test/src/main.rs | 10 ++++----- did-tezos/src/explorer.rs | 4 ++-- did-tezos/src/lib.rs | 4 ++-- did-web/src/lib.rs | 5 ++--- did-webkey/src/lib.rs | 13 +++++------- ssi-dids/src/did_resolve.rs | 41 +++++++++++++------------------------ vc-test/src/main.rs | 6 +++--- 13 files changed, 49 insertions(+), 69 deletions(-) diff --git a/did-ethr/src/lib.rs b/did-ethr/src/lib.rs index 16f7b3e65..9749d0dd1 100644 --- a/did-ethr/src/lib.rs +++ b/did-ethr/src/lib.rs @@ -97,7 +97,7 @@ fn resolve_pk( Ok(pk_bytes) => pk_bytes, Err(e) => { return ( - ResolutionMetadata::from_error(&format!("Unable to parse key: {}", e)), + ResolutionMetadata::from_error(&format!("Unable to parse key: {e}")), None, None, ); @@ -107,7 +107,7 @@ fn resolve_pk( Ok(hash) => hash, Err(e) => { return ( - ResolutionMetadata::from_error(&format!("Unable to hash account address: {}", e)), + ResolutionMetadata::from_error(&format!("Unable to hash account address: {e}")), None, None, ) @@ -309,7 +309,7 @@ impl DIDMethod for DIDEthr { Ok(hash) => hash, _ => return None, }; - let did = format!("did:ethr:{}", hash); + let did = format!("did:ethr:{hash}"); Some(did) } diff --git a/did-ion/src/sidetree.rs b/did-ion/src/sidetree.rs index 6dfbb0b93..03ae864b6 100644 --- a/did-ion/src/sidetree.rs +++ b/did-ion/src/sidetree.rs @@ -1329,7 +1329,7 @@ impl fmt::Display for SidetreeDID { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "did:{}:", S::METHOD)?; if let Some(network) = S::NETWORK { - write!(f, "{}:", network)?; + write!(f, "{network}:")?; } match self { Self::Short { did_suffix } => f.write_str(&did_suffix.0), @@ -1395,7 +1395,7 @@ pub struct HTTPSidetreeDIDResolver { impl HTTPSidetreeDIDResolver { pub fn new(sidetree_api_url: &str) -> Self { - let identifiers_url = format!("{}identifiers/", sidetree_api_url); + let identifiers_url = format!("{sidetree_api_url}identifiers/"); Self { http_did_resolver: HTTPDIDResolver::new(&identifiers_url), _marker: PhantomData, @@ -1571,7 +1571,7 @@ impl fmt::Display for SidetreeAPIError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Sidetree error {}", self.code)?; if let Some(ref message) = self.message { - write!(f, ": {}", message)?; + write!(f, ": {message}")?; } Ok(()) } @@ -1621,7 +1621,7 @@ impl DIDMethod for SidetreeClient { .endpoint .as_ref() .ok_or_else(|| anyhow!("Missing Sidetree REST API endpoint"))?; - let url = format!("{}operations/", endpoint); + let url = format!("{endpoint}operations/"); let client = Client::builder().build().context("Build HTTP client")?; let resp = client .post(url) diff --git a/did-key/src/lib.rs b/did-key/src/lib.rs index 70113002e..57a582189 100644 --- a/did-key/src/lib.rs +++ b/did-key/src/lib.rs @@ -237,7 +237,7 @@ impl DIDResolver for DIDKey { ]), id: did.to_string(), verification_method: Some(vec![VerificationMethod::Map(VerificationMethodMap { - id: format!("{}#{}", did, method_specific_id), + id: format!("{did}#{method_specific_id}"), type_: vm_type, controller: did.to_string(), public_key_jwk: Some(jwk), diff --git a/did-onion/src/lib.rs b/did-onion/src/lib.rs index 5d0b9661a..7b72c07b5 100644 --- a/did-onion/src/lib.rs +++ b/did-onion/src/lib.rs @@ -22,7 +22,7 @@ pub struct DIDOnion { impl DIDOnion { fn with_port(port: usize) -> Self { Self { - proxy_url: format!("socks5h://127.0.0.1:{}", port), + proxy_url: format!("socks5h://127.0.0.1:{port}"), } } } @@ -51,7 +51,7 @@ fn did_onion_url(did: &str) -> Result { Some(_) => parts.collect::>().join("/"), None => ".well-known".to_string(), }; - let url = format!("http://{}.onion/{}/did.json", onion_address, path); + let url = format!("http://{onion_address}.onion/{path}/did.json"); Ok(url) } @@ -113,7 +113,7 @@ impl DIDResolver for DIDOnion { Ok(proxy) => client_builder.proxy(proxy), Err(err) => { return ( - ResolutionMetadata::from_error(&format!("Error constructing proxy: {}", err)), + ResolutionMetadata::from_error(&format!("Error constructing proxy: {err}")), Vec::new(), None, ) @@ -123,7 +123,7 @@ impl DIDResolver for DIDOnion { Ok(c) => c, Err(err) => { return ( - ResolutionMetadata::from_error(&format!("Error building HTTP client: {}", err)), + ResolutionMetadata::from_error(&format!("Error building HTTP client: {err}")), Vec::new(), None, ) @@ -137,10 +137,7 @@ impl DIDResolver for DIDOnion { Ok(req) => req, Err(err) => { return ( - ResolutionMetadata::from_error(&format!( - "Error sending HTTP request : {}", - err - )), + ResolutionMetadata::from_error(&format!("Error sending HTTP request: {err}")), Vec::new(), None, ) diff --git a/did-pkh/src/lib.rs b/did-pkh/src/lib.rs index 987306598..9e222a948 100644 --- a/did-pkh/src/lib.rs +++ b/did-pkh/src/lib.rs @@ -631,7 +631,7 @@ fn generate_caip10_did(key: &JWK, name: &str) -> Result { "aleo" => generate_caip10_aleo(key, reference_opt)?, _ => return Err("Namespace not supported".to_string()), }; - Ok(format!("did:pkh:{}", account_id)) + Ok(format!("did:pkh:{account_id}")) } impl DIDMethod for DIDPKH { @@ -665,7 +665,7 @@ impl DIDMethod for DIDPKH { Some(addr) => addr, None => return None, }; - let did = format!("did:pkh:{}:{}", pkh_name, addr); + let did = format!("did:pkh:{pkh_name}:{addr}"); Some(did) } diff --git a/did-sol/src/lib.rs b/did-sol/src/lib.rs index d173eebf3..d2c162a40 100644 --- a/did-sol/src/lib.rs +++ b/did-sol/src/lib.rs @@ -182,7 +182,7 @@ impl DIDMethod for DIDSol { let did = match jwk.params { Params::OKP(ref params) if params.curve == "Ed25519" => { let addr = bs58::encode(¶ms.public_key.0).into_string(); - format!("did:sol:{}", addr) + format!("did:sol:{addr}") } _ => { dbg!(&jwk.params); diff --git a/did-test/src/main.rs b/did-test/src/main.rs index 37414795e..27b8c262f 100644 --- a/did-test/src/main.rs +++ b/did-test/src/main.rs @@ -372,7 +372,7 @@ impl ResolverOutcome { return Self::RepresentationNotSupportedErrorOutcome } ERROR_NOT_FOUND => return Self::NotFoundErrorOutcome, - _ => panic!("Unknown outcome for error: {}", error), + _ => panic!("Unknown outcome for error: {error}"), } } if deactivated == Some(true) { @@ -828,7 +828,7 @@ async fn report_method(mut args: Args) { "onion" => report_method_onion().await, "pkh" => report_method_pkh().await, "webkey" => report_method_webkey().await, - method => panic!("unknown method {}", method), + method => panic!("unknown method {method}"), } } @@ -842,7 +842,7 @@ async fn report_resolver(mut args: Args) { "onion" => report_resolver_onion().await, "pkh" => report_resolver_pkh().await, "webkey" => report_resolver_webkey().await, - method => panic!("unknown method {}", method), + method => panic!("unknown method {method}"), } } @@ -856,7 +856,7 @@ async fn report_dereferencer(mut args: Args) { "onion" => report_dereferencer_onion().await, "pkh" => report_dereferencer_pkh().await, "webkey" => report_dereferencer_webkey().await, - method => panic!("unknown method {}", method), + method => panic!("unknown method {method}"), } } @@ -869,6 +869,6 @@ async fn main() { "method" => report_method(args).await, "resolver" => report_resolver(args).await, "dereferencer" => report_dereferencer(args).await, - section => panic!("unknown section {}", section), + section => panic!("unknown section {section}"), } } diff --git a/did-tezos/src/explorer.rs b/did-tezos/src/explorer.rs index 886809e28..22083d526 100644 --- a/did-tezos/src/explorer.rs +++ b/did-tezos/src/explorer.rs @@ -54,7 +54,7 @@ pub async fn execute_service_view(tzkt_url: &str, did: &str, contract: &str) -> .build()?; let url = Url::parse(tzkt_url)?; let service_result: ServiceResult = client - .get(url.join(&format!("/v1/contracts/{}/storage", contract))?) + .get(url.join(&format!("/v1/contracts/{contract}/storage"))?) .send() .await? .json() @@ -78,7 +78,7 @@ pub async fn execute_auth_view(tzkt_url: &str, contract: &str) -> Result u.clone(), - None => format!("https://api.{}.tzkt.io", network), + None => format!("https://api.{network}.tzkt.io"), }; let mut tzkt_url = &default_url; if let Some(s) = &input_metadata.property_set { @@ -413,7 +413,7 @@ impl DIDTz { id: String::from(vm_didurl.clone()), type_: proof_type.to_string(), controller: did.to_string(), - blockchain_account_id: Some(format!("tezos:{}:{}", genesis_block_hash, address)), + blockchain_account_id: Some(format!("tezos:{genesis_block_hash}:{address}")), ..Default::default() })]), authentication: match public_key { diff --git a/did-web/src/lib.rs b/did-web/src/lib.rs index ff23c00e4..f50f51da3 100644 --- a/did-web/src/lib.rs +++ b/did-web/src/lib.rs @@ -118,7 +118,7 @@ impl DIDResolver for DIDWeb { Ok(c) => c, Err(err) => { return ( - ResolutionMetadata::from_error(&format!("Error building HTTP client: {}", err)), + ResolutionMetadata::from_error(&format!("Error building HTTP client: {err}")), Vec::new(), None, ) @@ -133,8 +133,7 @@ impl DIDResolver for DIDWeb { Err(err) => { return ( ResolutionMetadata::from_error(&format!( - "Error sending HTTP request ({}): {}", - url, err + "Error sending HTTP request ({url}): {err}" )), Vec::new(), None, diff --git a/did-webkey/src/lib.rs b/did-webkey/src/lib.rs index 19bbbbf28..8da3da9d9 100644 --- a/did-webkey/src/lib.rs +++ b/did-webkey/src/lib.rs @@ -63,7 +63,7 @@ fn gpg_pk_to_vm(did: &str, pk: SignedPublicKey) -> Result<(VerificationMethodMap let fingerprint = pk .fingerprint() .iter() - .fold(String::new(), |acc, &x| format!("{}{:02X}", acc, x)); + .fold(String::new(), |acc, &x| format!("{acc}{x:02X}")); let vm_url = DIDURL { did: did.to_string(), fragment: Some(fingerprint.clone()), @@ -228,7 +228,7 @@ fn parse_did_webkey_url(did: &str) -> Result<(DIDWebKeyType, String), Resolution } }; #[allow(unused_mut)] - let mut url = format!("https://{}/{}", domain_name, path); + let mut url = format!("https://{domain_name}/{path}"); #[cfg(test)] PROXY.with(|proxy| { if let Some(ref proxy) = *proxy.borrow() { @@ -259,7 +259,7 @@ impl DIDResolver for DIDWebKey { Ok(c) => c, Err(err) => { return ( - ResolutionMetadata::from_error(&format!("Error building HTTP client: {}", err)), + ResolutionMetadata::from_error(&format!("Error building HTTP client: {err}")), None, None, ) @@ -273,10 +273,7 @@ impl DIDResolver for DIDWebKey { Ok(req) => req, Err(err) => { return ( - ResolutionMetadata::from_error(&format!( - "Error sending HTTP request : {}", - err - )), + ResolutionMetadata::from_error(&format!("Error sending HTTP request : {err}")), None, None, ) @@ -312,7 +309,7 @@ impl DIDResolver for DIDWebKey { ), Err(err) => { return ( - ResolutionMetadata::from_error(&format!("Error parsing keys: {}", err)), + ResolutionMetadata::from_error(&format!("Error parsing keys: {err}")), None, None, ) diff --git a/ssi-dids/src/did_resolve.rs b/ssi-dids/src/did_resolve.rs index f56954750..523b28d2a 100644 --- a/ssi-dids/src/did_resolve.rs +++ b/ssi-dids/src/did_resolve.rs @@ -868,10 +868,7 @@ fn transform_resolution_result( Ok(result) => result, Err(err) => { return ( - ResolutionMetadata::from_error(&format!( - "Error parsing resolution result: {}", - err - )), + ResolutionMetadata::from_error(&format!("Error parsing resolution result: {err}")), None, None, ) @@ -944,7 +941,7 @@ impl DIDResolver for HTTPDIDResolver { Ok(client) => client, Err(err) => { return ( - ResolutionMetadata::from_error(&format!("Error building HTTP client: {}", err)), + ResolutionMetadata::from_error(&format!("Error building HTTP client: {err}")), None, None, ); @@ -960,7 +957,7 @@ impl DIDResolver for HTTPDIDResolver { Ok(resp) => resp, Err(err) => { return ( - ResolutionMetadata::from_error(&format!("Error sending HTTP request: {}", err)), + ResolutionMetadata::from_error(&format!("Error sending HTTP request: {err}")), None, None, ) @@ -974,8 +971,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return ( ResolutionMetadata::from_error(&format!( - "Error reading HTTP header: {}", - err + "Error reading HTTP header: {err}" )), None, None, @@ -1014,8 +1010,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return ( ResolutionMetadata::from_error(&format!( - "Error parsing resolution response: {}", - err + "Error parsing resolution response: {err}" )), None, None, @@ -1034,7 +1029,7 @@ impl DIDResolver for HTTPDIDResolver { Ok(doc) => doc, Err(err) => { return ( - ResolutionMetadata::from_error(&format!("Error parsing DID document: {}", err)), + ResolutionMetadata::from_error(&format!("Error parsing DID document: {err}")), None, None, ) @@ -1058,8 +1053,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return Some(( DereferencingMetadata::from_error(&format!( - "Unable to serialize input metadata into query string: {}", - err + "Unable to serialize input metadata into query string: {err}" )), Content::Null, ContentMetadata::default(), @@ -1091,8 +1085,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return Some(( DereferencingMetadata::from_error(&format!( - "Error building HTTP client: {}", - err + "Error building HTTP client: {err}" )), Content::Null, ContentMetadata::default(), @@ -1110,8 +1103,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return Some(( DereferencingMetadata::from_error(&format!( - "Error sending HTTP request: {}", - err + "Error sending HTTP request: {err}" )), Content::Null, ContentMetadata::default(), @@ -1134,8 +1126,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return Some(( DereferencingMetadata::from_error(&format!( - "Error reading HTTP header: {}", - err + "Error reading HTTP header: {err}" )), Content::Null, ContentMetadata::default(), @@ -1149,8 +1140,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return Some(( DereferencingMetadata::from_error(&format!( - "Error reading HTTP response: {}", - err + "Error reading HTTP response: {err}" )), Content::Null, ContentMetadata::default(), @@ -1164,8 +1154,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return Some(( DereferencingMetadata::from_error(&format!( - "Error parsing DID document: {}", - err + "Error parsing DID document: {err}" )), Content::Null, ContentMetadata::default(), @@ -1182,8 +1171,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return Some(( DereferencingMetadata::from_error(&format!( - "Error parsing DID resolution result: {}", - err + "Error parsing DID resolution result: {err}" )), Content::Null, ContentMetadata::default(), @@ -1206,8 +1194,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return Some(( DereferencingMetadata::from_error(&format!( - "Error parsing JSON: {}", - err + "Error parsing JSON: {err}" )), Content::Null, ContentMetadata::default(), diff --git a/vc-test/src/main.rs b/vc-test/src/main.rs index 0e3b2290f..668d11c24 100644 --- a/vc-test/src/main.rs +++ b/vc-test/src/main.rs @@ -103,14 +103,14 @@ async fn main() { (true, "--jwt-no-jws") => jwt_no_jws = true, (true, "--jwt-presentation") => jwt_presentation = true, (true, "--jwt-decode") => jwt_decode = true, - (true, _) => panic!("Unexpected option '{}'", arg), + (true, _) => panic!("Unexpected option '{arg}'"), (false, _) => { if cmd.is_none() { cmd = Option::Some(arg); } else if filename.is_none() { filename = Option::Some(arg); } else { - panic!("Unexpected argument '{}'", arg); + panic!("Unexpected argument '{arg}'"); } } } @@ -157,7 +157,7 @@ async fn main() { write_out(output); } _ => { - eprintln!("Unexpected command '{}'", cmd_str); + eprintln!("Unexpected command '{cmd_str}'"); std::process::exit(1); } }