/rust/registry/src/index.crates.io-6f17d22bba15001f/untrusted-0.9.0/src/no_panic.rs
Line | Count | Source (jump to first uncovered line) |
1 | | /// A wrapper around a slice that exposes no functions that can panic. |
2 | | /// |
3 | | /// Intentionally avoids implementing `Debug`, `Eq`, and `PartialEq` to avoid |
4 | | /// creating a side channel that would leak information about the value. |
5 | | #[derive(Clone, Copy)] |
6 | | pub struct Slice<'a> { |
7 | | bytes: &'a [u8], |
8 | | } |
9 | | |
10 | | impl<'a> Slice<'a> { |
11 | | #[inline] |
12 | 0 | pub const fn new(bytes: &'a [u8]) -> Self { |
13 | 0 | Self { bytes } |
14 | 0 | } |
15 | | |
16 | | #[inline] |
17 | 0 | pub fn get(&self, i: usize) -> Option<&u8> { |
18 | 0 | self.bytes.get(i) |
19 | 0 | } Unexecuted instantiation: <untrusted::no_panic::Slice>::get Unexecuted instantiation: <untrusted::no_panic::Slice>::get |
20 | | |
21 | | #[inline] |
22 | 0 | pub fn subslice(&self, r: core::ops::Range<usize>) -> Option<Self> { |
23 | 0 | self.bytes.get(r).map(|bytes| Self { bytes }) Unexecuted instantiation: <untrusted::no_panic::Slice>::subslice::{closure#0} Unexecuted instantiation: <untrusted::no_panic::Slice>::subslice::{closure#0} |
24 | 0 | } Unexecuted instantiation: <untrusted::no_panic::Slice>::subslice Unexecuted instantiation: <untrusted::no_panic::Slice>::subslice |
25 | | |
26 | | #[inline] |
27 | 0 | pub fn is_empty(&self) -> bool { |
28 | 0 | self.bytes.is_empty() |
29 | 0 | } Unexecuted instantiation: <untrusted::no_panic::Slice>::is_empty Unexecuted instantiation: <untrusted::no_panic::Slice>::is_empty |
30 | | |
31 | | #[inline] |
32 | 0 | pub fn len(&self) -> usize { |
33 | 0 | self.bytes.len() |
34 | 0 | } Unexecuted instantiation: <untrusted::no_panic::Slice>::len Unexecuted instantiation: <untrusted::no_panic::Slice>::len |
35 | | |
36 | | #[inline] |
37 | 0 | pub fn as_slice_less_safe(&self) -> &'a [u8] { |
38 | 0 | self.bytes |
39 | 0 | } Unexecuted instantiation: <untrusted::no_panic::Slice>::as_slice_less_safe Unexecuted instantiation: <untrusted::no_panic::Slice>::as_slice_less_safe |
40 | | } |