/rust/registry/src/index.crates.io-1949cf8c6b5b557f/untrusted-0.9.0/src/no_panic.rs
Line | Count | Source |
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 | 1.16k | pub const fn new(bytes: &'a [u8]) -> Self { |
13 | 1.16k | Self { bytes } |
14 | 1.16k | } |
15 | | |
16 | | #[inline] |
17 | 80.4k | pub fn get(&self, i: usize) -> Option<&u8> { |
18 | 80.4k | self.bytes.get(i) |
19 | 80.4k | } <untrusted::no_panic::Slice>::get Line | Count | Source | 17 | 80.4k | pub fn get(&self, i: usize) -> Option<&u8> { | 18 | 80.4k | self.bytes.get(i) | 19 | 80.4k | } |
Unexecuted instantiation: <untrusted::no_panic::Slice>::get |
20 | | |
21 | | #[inline] |
22 | 35.4k | pub fn subslice(&self, r: core::ops::Range<usize>) -> Option<Self> { |
23 | 35.4k | self.bytes.get(r).map(|bytes| Self { bytes })<untrusted::no_panic::Slice>::subslice::{closure#0}Line | Count | Source | 23 | 35.4k | self.bytes.get(r).map(|bytes| Self { bytes }) |
Unexecuted instantiation: <untrusted::no_panic::Slice>::subslice::{closure#0} |
24 | 35.4k | } <untrusted::no_panic::Slice>::subslice Line | Count | Source | 22 | 35.4k | pub fn subslice(&self, r: core::ops::Range<usize>) -> Option<Self> { | 23 | 35.4k | self.bytes.get(r).map(|bytes| Self { bytes }) | 24 | 35.4k | } |
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 | 29.5k | pub fn len(&self) -> usize { |
33 | 29.5k | self.bytes.len() |
34 | 29.5k | } Unexecuted instantiation: <untrusted::no_panic::Slice>::len <untrusted::no_panic::Slice>::len Line | Count | Source | 32 | 29.5k | pub fn len(&self) -> usize { | 33 | 29.5k | self.bytes.len() | 34 | 29.5k | } |
Unexecuted instantiation: <untrusted::no_panic::Slice>::len |
35 | | |
36 | | #[inline] |
37 | 16.0k | pub fn as_slice_less_safe(&self) -> &'a [u8] { |
38 | 16.0k | self.bytes |
39 | 16.0k | } <untrusted::no_panic::Slice>::as_slice_less_safe Line | Count | Source | 37 | 16.0k | pub fn as_slice_less_safe(&self) -> &'a [u8] { | 38 | 16.0k | self.bytes | 39 | 16.0k | } |
Unexecuted instantiation: <untrusted::no_panic::Slice>::as_slice_less_safe |
40 | | } |