diff --git a/pkstrings/src/lib.rs b/pkstrings/src/lib.rs index ef14f2d..0d0906e 100644 --- a/pkstrings/src/lib.rs +++ b/pkstrings/src/lib.rs @@ -122,6 +122,21 @@ impl fmt::Display for PKString { } } +impl TryFrom for PKString { + type Error = Error; + + fn try_from(ord: u8) -> Result { + 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 { type Error = Error;