/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 | 7.90k | pub const fn new(bytes: &'a [u8]) -> Self { |
13 | 7.90k | Self { bytes } |
14 | 7.90k | } |
15 | | |
16 | | #[inline] |
17 | 9.85k | pub fn get(&self, i: usize) -> Option<&u8> { |
18 | 9.85k | self.bytes.get(i) |
19 | 9.85k | } <untrusted::no_panic::Slice>::get Line | Count | Source | 17 | 9.85k | pub fn get(&self, i: usize) -> Option<&u8> { | 18 | 9.85k | self.bytes.get(i) | 19 | 9.85k | } |
Unexecuted instantiation: <untrusted::no_panic::Slice>::get |
20 | | |
21 | | #[inline] |
22 | 6.38k | pub fn subslice(&self, r: core::ops::Range<usize>) -> Option<Self> { |
23 | 6.38k | self.bytes.get(r).map(|bytes| Self { bytes })<untrusted::no_panic::Slice>::subslice::{closure#0}Line | Count | Source | 23 | 5.88k | self.bytes.get(r).map(|bytes| Self { bytes }) |
Unexecuted instantiation: <untrusted::no_panic::Slice>::subslice::{closure#0} |
24 | 6.38k | } <untrusted::no_panic::Slice>::subslice Line | Count | Source | 22 | 6.38k | pub fn subslice(&self, r: core::ops::Range<usize>) -> Option<Self> { | 23 | 6.38k | self.bytes.get(r).map(|bytes| Self { bytes }) | 24 | 6.38k | } |
Unexecuted instantiation: <untrusted::no_panic::Slice>::subslice |
25 | | |
26 | | #[inline] |
27 | 5.32k | pub fn is_empty(&self) -> bool { |
28 | 5.32k | self.bytes.is_empty() |
29 | 5.32k | } <untrusted::no_panic::Slice>::is_empty Line | Count | Source | 27 | 5.32k | pub fn is_empty(&self) -> bool { | 28 | 5.32k | self.bytes.is_empty() | 29 | 5.32k | } |
Unexecuted instantiation: <untrusted::no_panic::Slice>::is_empty |
30 | | |
31 | | #[inline] |
32 | 5.41k | pub fn len(&self) -> usize { |
33 | 5.41k | self.bytes.len() |
34 | 5.41k | } <untrusted::no_panic::Slice>::len Line | Count | Source | 32 | 5.41k | pub fn len(&self) -> usize { | 33 | 5.41k | self.bytes.len() | 34 | 5.41k | } |
Unexecuted instantiation: <untrusted::no_panic::Slice>::len |
35 | | |
36 | | #[inline] |
37 | 10.0k | pub fn as_slice_less_safe(&self) -> &'a [u8] { |
38 | 10.0k | self.bytes |
39 | 10.0k | } <untrusted::no_panic::Slice>::as_slice_less_safe Line | Count | Source | 37 | 10.0k | pub fn as_slice_less_safe(&self) -> &'a [u8] { | 38 | 10.0k | self.bytes | 39 | 10.0k | } |
Unexecuted instantiation: <untrusted::no_panic::Slice>::as_slice_less_safe |
40 | | } |