pkstrings: new as_slice method

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2021-11-15 13:34:59 +01:00
parent 7817909a69
commit 31290b2bbc
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2
2 changed files with 11 additions and 12 deletions

View file

@ -222,8 +222,8 @@ impl From<PKString> for String {
}
}
// impl PKString {
// fn as_slice(&self) -> &[u8] {
// self.0.as_slice()
// }
// }
impl PKString {
pub fn as_slice(&self) -> &[u8] {
self.0.as_slice()
}
}

View file

@ -112,10 +112,9 @@ fn test_from_string() {
}
}
// #[test]
// fn test_as_slice_u8() {
// let gary: Vec<u8> = vec![0x86, 0x80, 0x91, 0x98];
// let pkstr: PKString = PKString::try_from(gary.clone()).unwrap();
// let res: &[u8] = pkstr.as_slice();
// assert_eq!(res, gary.as_slice());
// }
#[test]
fn test_as_slice_u8() {
let pkstr: PKString = PKString::try_from(GARY_SLICE_U8).unwrap();
let res: &[u8] = pkstr.as_slice();
assert_eq!(res, GARY_SLICE_U8);
}