Implement Display for Lang
This commit is contained in:
parent
8d09289d48
commit
af0410191e
1 changed files with 15 additions and 2 deletions
|
@ -4,8 +4,8 @@
|
||||||
//! OpenPGP card data objects (DO)
|
//! OpenPGP card data objects (DO)
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use std::convert::TryFrom;
|
use std::convert::{TryFrom, TryInto};
|
||||||
use std::convert::TryInto;
|
use std::fmt::{Display, Formatter};
|
||||||
use std::time::{Duration, UNIX_EPOCH};
|
use std::time::{Duration, UNIX_EPOCH};
|
||||||
|
|
||||||
use crate::{algorithm::Algo, tlv::Tlv, Error, KeySet, KeyType};
|
use crate::{algorithm::Algo, tlv::Tlv, Error, KeySet, KeyType};
|
||||||
|
@ -304,6 +304,19 @@ pub enum Lang {
|
||||||
Invalid(u8),
|
Invalid(u8),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for Lang {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Value(v) => {
|
||||||
|
write!(f, "{}{}", v[0] as char, v[1] as char)
|
||||||
|
}
|
||||||
|
Self::Invalid(v) => {
|
||||||
|
write!(f, "{:x?}", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<(char, char)> for Lang {
|
impl From<(char, char)> for Lang {
|
||||||
fn from(c: (char, char)) -> Self {
|
fn from(c: (char, char)) -> Self {
|
||||||
Lang::Value([c.0 as u8, c.1 as u8])
|
Lang::Value([c.0 as u8, c.1 as u8])
|
||||||
|
|
Loading…
Reference in a new issue