Coverage Report

Created: 2026-07-14 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/zlib-rs-0.6.6/src/weak_slice.rs
Line
Count
Source
1
use core::marker::PhantomData;
2
3
/// a mutable "slice" (bundle of pointer and length). The main goal of this type is passing MIRI
4
/// with stacked borrows. In particular, storing a standard slice in data structures violates the
5
/// stacked borrows rule when that slice is deallocated. By only materializing the slice when
6
/// needed for data access, hence bounding the lifetime more tightly, this restriction is circumvented.
7
#[derive(Debug)]
8
pub(crate) struct WeakSliceMut<'a, T> {
9
    ptr: *mut T,
10
    len: usize,
11
    _marker: PhantomData<&'a mut [T]>,
12
}
13
14
impl<'a, T> WeakSliceMut<'a, T> {
15
    /// # Safety
16
    ///
17
    /// The arguments must satisfy the requirements of [`core::slice::from_raw_parts_mut`]. The
18
    /// difference versus a slice is that the slice requirements are only enforced when a slice is
19
    /// needed, so in practice we mostly get the bounds checking and other convenient slice APIs,
20
    /// without the exact correctness constraints of a rust core/std slice.
21
36.4k
    pub(crate) unsafe fn from_raw_parts_mut(ptr: *mut T, len: usize) -> Self {
22
36.4k
        Self {
23
36.4k
            ptr,
24
36.4k
            len,
25
36.4k
            _marker: PhantomData,
26
36.4k
        }
27
36.4k
    }
<zlib_rs::weak_slice::WeakSliceMut<core::mem::maybe_uninit::MaybeUninit<u8>>>::from_raw_parts_mut
Line
Count
Source
21
29.8k
    pub(crate) unsafe fn from_raw_parts_mut(ptr: *mut T, len: usize) -> Self {
22
29.8k
        Self {
23
29.8k
            ptr,
24
29.8k
            len,
25
29.8k
            _marker: PhantomData,
26
29.8k
        }
27
29.8k
    }
<zlib_rs::weak_slice::WeakSliceMut<u8>>::from_raw_parts_mut
Line
Count
Source
21
6.56k
    pub(crate) unsafe fn from_raw_parts_mut(ptr: *mut T, len: usize) -> Self {
22
6.56k
        Self {
23
6.56k
            ptr,
24
6.56k
            len,
25
6.56k
            _marker: PhantomData,
26
6.56k
        }
27
6.56k
    }
Unexecuted instantiation: <zlib_rs::weak_slice::WeakSliceMut<u16>>::from_raw_parts_mut
28
29
0
    pub(crate) fn into_raw_parts(self) -> (*mut T, usize) {
30
0
        (self.ptr, self.len)
31
0
    }
32
33
0
    pub(crate) fn as_slice(&self) -> &'a [T] {
34
0
        unsafe { core::slice::from_raw_parts(self.ptr, self.len) }
35
0
    }
Unexecuted instantiation: <zlib_rs::weak_slice::WeakSliceMut<core::mem::maybe_uninit::MaybeUninit<u8>>>::as_slice
Unexecuted instantiation: <zlib_rs::weak_slice::WeakSliceMut<u8>>::as_slice
Unexecuted instantiation: <zlib_rs::weak_slice::WeakSliceMut<u16>>::as_slice
36
37
5.67M
    pub(crate) fn as_mut_slice(&mut self) -> &mut [T] {
38
5.67M
        unsafe { core::slice::from_raw_parts_mut(self.ptr, self.len) }
39
5.67M
    }
<zlib_rs::weak_slice::WeakSliceMut<core::mem::maybe_uninit::MaybeUninit<u8>>>::as_mut_slice
Line
Count
Source
37
5.67M
    pub(crate) fn as_mut_slice(&mut self) -> &mut [T] {
38
5.67M
        unsafe { core::slice::from_raw_parts_mut(self.ptr, self.len) }
39
5.67M
    }
<zlib_rs::weak_slice::WeakSliceMut<u8>>::as_mut_slice
Line
Count
Source
37
5.31k
    pub(crate) fn as_mut_slice(&mut self) -> &mut [T] {
38
5.31k
        unsafe { core::slice::from_raw_parts_mut(self.ptr, self.len) }
39
5.31k
    }
Unexecuted instantiation: <zlib_rs::weak_slice::WeakSliceMut<u16>>::as_mut_slice
40
41
6.04k
    pub(crate) fn as_ptr(&self) -> *const T {
42
6.04k
        self.ptr
43
6.04k
    }
<zlib_rs::weak_slice::WeakSliceMut<core::mem::maybe_uninit::MaybeUninit<u8>>>::as_ptr
Line
Count
Source
41
6.04k
    pub(crate) fn as_ptr(&self) -> *const T {
42
6.04k
        self.ptr
43
6.04k
    }
Unexecuted instantiation: <zlib_rs::weak_slice::WeakSliceMut<u8>>::as_ptr
44
45
5.31k
    pub(crate) fn as_mut_ptr(&mut self) -> *mut T {
46
5.31k
        self.ptr
47
5.31k
    }
<zlib_rs::weak_slice::WeakSliceMut<core::mem::maybe_uninit::MaybeUninit<u8>>>::as_mut_ptr
Line
Count
Source
45
5.31k
    pub(crate) fn as_mut_ptr(&mut self) -> *mut T {
46
5.31k
        self.ptr
47
5.31k
    }
Unexecuted instantiation: <zlib_rs::weak_slice::WeakSliceMut<u8>>::as_mut_ptr
48
49
7.00M
    pub(crate) fn len(&self) -> usize {
50
7.00M
        self.len
51
7.00M
    }
<zlib_rs::weak_slice::WeakSliceMut<core::mem::maybe_uninit::MaybeUninit<u8>>>::len
Line
Count
Source
49
6.89M
    pub(crate) fn len(&self) -> usize {
50
6.89M
        self.len
51
6.89M
    }
<zlib_rs::weak_slice::WeakSliceMut<u8>>::len
Line
Count
Source
49
111k
    pub(crate) fn len(&self) -> usize {
50
111k
        self.len
51
111k
    }
52
53
37.0k
    pub(crate) fn is_empty(&self) -> bool {
54
37.0k
        self.len() == 0
55
37.0k
    }
56
57
13.1k
    pub(crate) fn empty() -> Self {
58
13.1k
        let buf = &mut [];
59
13.1k
        Self {
60
13.1k
            ptr: buf.as_mut_ptr(),
61
13.1k
            len: buf.len(),
62
13.1k
            _marker: PhantomData,
63
13.1k
        }
64
13.1k
    }
65
}
66
67
#[derive(Debug)]
68
pub(crate) struct WeakArrayMut<'a, T, const N: usize> {
69
    ptr: *mut [T; N],
70
    _marker: PhantomData<&'a mut [T; N]>,
71
}
72
73
impl<'a, T, const N: usize> WeakArrayMut<'a, T, N> {
74
    /// # Safety
75
    ///
76
    /// The pointer must be [convertable to a reference](https://doc.rust-lang.org/std/ptr/index.html#pointer-to-reference-conversion).
77
0
    pub(crate) unsafe fn from_ptr(ptr: *mut [T; N]) -> Self {
78
0
        Self {
79
0
            ptr,
80
0
            _marker: PhantomData,
81
0
        }
82
0
    }
83
84
0
    pub(crate) fn as_slice(&self) -> &'a [T] {
85
0
        unsafe { core::slice::from_raw_parts(self.ptr.cast(), N) }
86
0
    }
87
88
0
    pub(crate) fn as_mut_slice(&mut self) -> &mut [T] {
89
0
        unsafe { core::slice::from_raw_parts_mut(self.ptr.cast(), N) }
90
0
    }
91
92
0
    pub(crate) fn as_ptr(&self) -> *const [T; N] {
93
0
        self.ptr
94
0
    }
95
}