pkstrings: impl TryFrom<u8> for PKString
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
19b0f3989e
commit
0c0799994d
1 changed files with 15 additions and 0 deletions
|
@ -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 {
|
||||
type Error = Error;
|
||||
|
||||
|
|
Loading…
Reference in a new issue