/rust/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.15.4/src/scopeguard.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // Extracted from the scopeguard crate |
2 | | use core::{ |
3 | | mem::ManuallyDrop, |
4 | | ops::{Deref, DerefMut}, |
5 | | ptr, |
6 | | }; |
7 | | |
8 | | pub struct ScopeGuard<T, F> |
9 | | where |
10 | | F: FnMut(&mut T), |
11 | | { |
12 | | dropfn: F, |
13 | | value: T, |
14 | | } |
15 | | |
16 | | #[inline] |
17 | 0 | pub fn guard<T, F>(value: T, dropfn: F) -> ScopeGuard<T, F> |
18 | 0 | where |
19 | 0 | F: FnMut(&mut T), |
20 | 0 | { |
21 | 0 | ScopeGuard { dropfn, value } |
22 | 0 | } Unexecuted instantiation: hashbrown::scopeguard::guard::<hashbrown::raw::RawTableInner, <hashbrown::raw::RawTableInner>::prepare_resize<hashbrown::raw::alloc::inner::Global>::{closure#0}> Unexecuted instantiation: hashbrown::scopeguard::guard::<&mut hashbrown::raw::RawTableInner, <hashbrown::raw::RawTableInner>::rehash_in_place::{closure#0}> Unexecuted instantiation: hashbrown::scopeguard::guard::<_, _> |
23 | | |
24 | | impl<T, F> ScopeGuard<T, F> |
25 | | where |
26 | | F: FnMut(&mut T), |
27 | | { |
28 | | #[inline] |
29 | 0 | pub fn into_inner(guard: Self) -> T { |
30 | 0 | // Cannot move out of Drop-implementing types, so |
31 | 0 | // ptr::read the value out of a ManuallyDrop<Self> |
32 | 0 | // Don't use mem::forget as that might invalidate value |
33 | 0 | let guard = ManuallyDrop::new(guard); |
34 | 0 | unsafe { |
35 | 0 | let value = ptr::read(&guard.value); |
36 | 0 | // read the closure so that it is dropped |
37 | 0 | let _ = ptr::read(&guard.dropfn); |
38 | 0 | value |
39 | 0 | } |
40 | 0 | } |
41 | | } |
42 | | |
43 | | impl<T, F> Deref for ScopeGuard<T, F> |
44 | | where |
45 | | F: FnMut(&mut T), |
46 | | { |
47 | | type Target = T; |
48 | | #[inline] |
49 | 0 | fn deref(&self) -> &T { |
50 | 0 | &self.value |
51 | 0 | } Unexecuted instantiation: <hashbrown::scopeguard::ScopeGuard<hashbrown::raw::RawTableInner, <hashbrown::raw::RawTableInner>::prepare_resize<hashbrown::raw::alloc::inner::Global>::{closure#0}> as core::ops::deref::Deref>::deref Unexecuted instantiation: <hashbrown::scopeguard::ScopeGuard<&mut hashbrown::raw::RawTableInner, <hashbrown::raw::RawTableInner>::rehash_in_place::{closure#0}> as core::ops::deref::Deref>::deref Unexecuted instantiation: <hashbrown::scopeguard::ScopeGuard<_, _> as core::ops::deref::Deref>::deref |
52 | | } |
53 | | |
54 | | impl<T, F> DerefMut for ScopeGuard<T, F> |
55 | | where |
56 | | F: FnMut(&mut T), |
57 | | { |
58 | | #[inline] |
59 | 0 | fn deref_mut(&mut self) -> &mut T { |
60 | 0 | &mut self.value |
61 | 0 | } Unexecuted instantiation: <hashbrown::scopeguard::ScopeGuard<hashbrown::raw::RawTableInner, <hashbrown::raw::RawTableInner>::prepare_resize<hashbrown::raw::alloc::inner::Global>::{closure#0}> as core::ops::deref::DerefMut>::deref_mut Unexecuted instantiation: <hashbrown::scopeguard::ScopeGuard<&mut hashbrown::raw::RawTableInner, <hashbrown::raw::RawTableInner>::rehash_in_place::{closure#0}> as core::ops::deref::DerefMut>::deref_mut Unexecuted instantiation: <hashbrown::scopeguard::ScopeGuard<_, _> as core::ops::deref::DerefMut>::deref_mut |
62 | | } |
63 | | |
64 | | impl<T, F> Drop for ScopeGuard<T, F> |
65 | | where |
66 | | F: FnMut(&mut T), |
67 | | { |
68 | | #[inline] |
69 | 0 | fn drop(&mut self) { |
70 | 0 | (self.dropfn)(&mut self.value); |
71 | 0 | } Unexecuted instantiation: <hashbrown::scopeguard::ScopeGuard<hashbrown::raw::RawTableInner, <hashbrown::raw::RawTableInner>::prepare_resize<hashbrown::raw::alloc::inner::Global>::{closure#0}> as core::ops::drop::Drop>::drop Unexecuted instantiation: <hashbrown::scopeguard::ScopeGuard<&mut hashbrown::raw::RawTableInner, <hashbrown::raw::RawTableInner>::rehash_in_place::{closure#0}> as core::ops::drop::Drop>::drop Unexecuted instantiation: <hashbrown::scopeguard::ScopeGuard<_, _> as core::ops::drop::Drop>::drop |
72 | | } |