From ee276a2dc55fd55f22494e9e70187f060fb2f151 Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Tue, 29 Jan 2019 10:03:53 +0100 Subject: openpgp: Change TPKBuilder::add_userid to take an Into>. - Change TPKBuilder::add_userid to take an Into>> instead of a &str. --- openpgp-ffi/src/tpk.rs | 4 ++-- openpgp/src/tpk/builder.rs | 8 ++++++-- openpgp/src/tsk.rs | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/openpgp-ffi/src/tpk.rs b/openpgp-ffi/src/tpk.rs index a3df23b7..b4026604 100644 --- a/openpgp-ffi/src/tpk.rs +++ b/openpgp-ffi/src/tpk.rs @@ -613,8 +613,8 @@ pub extern "system" fn pgp_tpk_builder_add_userid { let tpkb = ffi_param_ref_mut!(tpkb); let tpkb_ = ffi_param_move!(*tpkb); - let uid = ffi_param_cstr!(uid).to_string_lossy().to_string(); - let tpkb_ = tpkb_.add_userid(uid.as_ref()); + let uid = ffi_param_cstr!(uid).to_string_lossy(); + let tpkb_ = tpkb_.add_userid(uid); *tpkb = box_raw!(tpkb_); } diff --git a/openpgp/src/tpk/builder.rs b/openpgp/src/tpk/builder.rs index ff4670ab..014ec5e4 100644 --- a/openpgp/src/tpk/builder.rs +++ b/openpgp/src/tpk/builder.rs @@ -1,3 +1,5 @@ +use std::borrow::Cow; + use time; use packet::{Features, KeyFlags}; use packet::Key; @@ -118,8 +120,10 @@ impl TPKBuilder { } /// Adds a new user ID. The first user ID added will be the primary user ID. - pub fn add_userid(mut self, uid: &str) -> Self { - self.userids.push(uid.to_string()); + pub fn add_userid<'a, S>(mut self, uid: S) -> Self + where S: Into> + { + self.userids.push(uid.into().into_owned()); self } diff --git a/openpgp/src/tsk.rs b/openpgp/src/tsk.rs index d9ec86bf..fff2a7ed 100644 --- a/openpgp/src/tsk.rs +++ b/openpgp/src/tsk.rs @@ -84,7 +84,7 @@ impl TSK { let mut key = TPKBuilder::autocrypt(None); match primary_uid.into() { - Some(uid) => { key = key.add_userid(&uid); } + Some(uid) => { key = key.add_userid(uid); } None => {} } -- cgit v1.2.3