Implement Display for Lang

This commit is contained in:
Heiko Schaefer 2022-02-25 11:31:29 +01:00
parent 8d09289d48
commit af0410191e
No known key found for this signature in database
GPG key ID: 4A849A1904CCBD7D

View file

@ -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])