pkstrings: impl TryFrom<u8> for PKString

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2021-11-14 01:46:22 +01:00
parent 19b0f3989e
commit 0c0799994d

View file

@ -122,6 +122,21 @@ impl fmt::Display for PKString {
} }
} }
impl TryFrom<u8> for PKString {
type Error = Error;
fn try_from(ord: u8) -> Result<PKString, Error> {
let mut buf = String::with_capacity(1);
match hextostr(ord) {
Some(chr) => buf.push(chr.clone()),
None => return Err(Error::InvalidCharacter),
}
Ok(PKString(buf))
}
}
impl TryFrom<&[u8]> for PKString { impl TryFrom<&[u8]> for PKString {
type Error = Error; type Error = Error;