Impl Display for Email, Fingerprint, KeyID.

- This allows for a more efficient formatting, and implements
    ToString for free.
This commit is contained in:
Justus Winter 2019-03-07 15:13:12 +01:00
parent 58c457a013
commit 95ab918661
No known key found for this signature in database
GPG Key ID: 686F55B4AB2B3386
2 changed files with 13 additions and 9 deletions

View File

@ -23,6 +23,7 @@ extern crate serde_json;
extern crate tempfile;
extern crate time;
extern crate url;
extern crate hex;
extern crate sequoia_openpgp as openpgp;
use openpgp::{

View File

@ -1,4 +1,5 @@
use std::convert::TryFrom;
use std::fmt;
use std::result;
use std::str::FromStr;
@ -32,9 +33,9 @@ impl TryFrom<&UserID> for Email {
}
}
impl ToString for Email {
fn to_string(&self) -> String {
self.0.clone()
impl fmt::Display for Email {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&self.0)
}
}
@ -97,9 +98,10 @@ impl TryFrom<sequoia_openpgp::Fingerprint> for Fingerprint {
}
}
impl ToString for Fingerprint {
fn to_string(&self) -> String {
hex::encode_upper(&self.0[..])
impl fmt::Display for Fingerprint {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use ::hex::ToHex;
self.0.write_hex_upper(f)
}
}
@ -162,9 +164,10 @@ impl From<Fingerprint> for KeyID {
}
}
impl ToString for KeyID {
fn to_string(&self) -> String {
hex::encode_upper(&self.0[..])
impl fmt::Display for KeyID {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use ::hex::ToHex;
self.0.write_hex_upper(f)
}
}