~soywod/pimalaya

email-lib: reduce cloning in fetch and format_key_server_uri v1 APPLIED

Perma Alesheikh: 1
 reduce cloning in fetch and format_key_server_uri

 2 files changed, 5 insertions(+), 5 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~soywod/pimalaya/patches/49341/mbox | git am -3
Learn more about email & git

[PATCH email-lib] reduce cloning in fetch and format_key_server_uri Export this patch

Since we can achieve the same goal without ownership of the values, and
&String and &str gives us the same results, we can just use &str and
remove the extra .clone.

Signed-off-by: Perma Alesheikh <me@prma.dev>
---
 pgp/src/hkp.rs  | 2 +-
 pgp/src/http.rs | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/pgp/src/hkp.rs b/pgp/src/hkp.rs
index f5565ed..805f7e8 100644
--- a/pgp/src/hkp.rs
+++ b/pgp/src/hkp.rs
@@ -13,7 +13,7 @@
/// Formats the given URI to match the HKP specs.
///
/// It basically add `/pks` plus few query params.
pub(crate) fn format_key_server_uri(uri: Uri, email: &String) -> Result<Uri> {
pub(crate) fn format_key_server_uri(uri: Uri, email: &str) -> Result<Uri> {
    let authority = uri.host().unwrap_or("localhost");
    let scheme = match uri.scheme_str() {
        Some("hkps") => "https",
diff --git a/pgp/src/http.rs b/pgp/src/http.rs
index 9a307fa..b39aaf2 100644
--- a/pgp/src/http.rs
+++ b/pgp/src/http.rs
@@ -33,13 +33,13 @@ pub enum Error {
/// belonging to the given email address.
async fn fetch(
    client: &Client<HttpsConnector<HttpConnector>>,
    email: &String,
    key_server: &String,
    email: &str,
    key_server: &str,
) -> Result<SignedPublicKey> {
    let uri: Uri = key_server
        .replace("<email>", email)
        .parse()
        .map_err(|err| Error::ParseUriError(err, key_server.clone()))?;
        .map_err(|err| Error::ParseUriError(err, key_server.to_owned()))?;

    let uri = match uri.scheme_str() {
        Some("hkp") | Some("hkps") => hkp::format_key_server_uri(uri, email).unwrap(),
@@ -58,7 +58,7 @@ async fn fetch(

    let cursor = Cursor::new(&*body);
    let (pkey, _) = SignedPublicKey::from_armor_single(cursor)
        .map_err(|err| Error::ParsePublicKeyError(err, uri.clone()))?;
        .map_err(|err| Error::ParsePublicKeyError(err, uri))?;

    Ok(pkey)
}
-- 
2.43.0