From 31290b2bbcc3099a952e65ffc009c66ff65aff65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 15 Nov 2021 13:34:59 +0100 Subject: [PATCH] pkstrings: new as_slice method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- pkstrings/src/pkstring.rs | 10 +++++----- pkstrings/src/tests.rs | 13 ++++++------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pkstrings/src/pkstring.rs b/pkstrings/src/pkstring.rs index 12d3792..1b308c9 100644 --- a/pkstrings/src/pkstring.rs +++ b/pkstrings/src/pkstring.rs @@ -222,8 +222,8 @@ impl From 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() + } +} diff --git a/pkstrings/src/tests.rs b/pkstrings/src/tests.rs index 16cb65f..2d0d543 100644 --- a/pkstrings/src/tests.rs +++ b/pkstrings/src/tests.rs @@ -112,10 +112,9 @@ fn test_from_string() { } } -// #[test] -// fn test_as_slice_u8() { -// let gary: Vec = 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); +}