/rust/registry/src/index.crates.io-6f17d22bba15001f/anyhow-1.0.86/src/ptr.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use alloc::boxed::Box; |
2 | | use core::marker::PhantomData; |
3 | | use core::ptr::NonNull; |
4 | | |
5 | | #[repr(transparent)] |
6 | | pub struct Own<T> |
7 | | where |
8 | | T: ?Sized, |
9 | | { |
10 | | pub ptr: NonNull<T>, |
11 | | } |
12 | | |
13 | | unsafe impl<T> Send for Own<T> where T: ?Sized {} |
14 | | |
15 | | unsafe impl<T> Sync for Own<T> where T: ?Sized {} |
16 | | |
17 | | impl<T> Copy for Own<T> where T: ?Sized {} |
18 | | |
19 | | impl<T> Clone for Own<T> |
20 | | where |
21 | | T: ?Sized, |
22 | | { |
23 | 0 | fn clone(&self) -> Self { |
24 | 0 | *self |
25 | 0 | } |
26 | | } |
27 | | |
28 | | impl<T> Own<T> |
29 | | where |
30 | | T: ?Sized, |
31 | | { |
32 | 4.50k | pub fn new(ptr: Box<T>) -> Self { |
33 | 4.50k | Own { |
34 | 4.50k | ptr: unsafe { NonNull::new_unchecked(Box::into_raw(ptr)) }, |
35 | 4.50k | } |
36 | 4.50k | } <anyhow::ptr::Own<anyhow::error::ErrorImpl<rhai::types::parse_error::ParseError>>>::new Line | Count | Source | 32 | 4.50k | pub fn new(ptr: Box<T>) -> Self { | 33 | 4.50k | Own { | 34 | 4.50k | ptr: unsafe { NonNull::new_unchecked(Box::into_raw(ptr)) }, | 35 | 4.50k | } | 36 | 4.50k | } |
Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl<anyhow::wrapper::MessageError<alloc::string::String>>>>::new Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl<anyhow::wrapper::MessageError<&str>>>>::new Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl<anyhow::wrapper::BoxedError>>>::new |
37 | | |
38 | 9.00k | pub fn cast<U: CastTo>(self) -> Own<U::Target> { |
39 | 9.00k | Own { |
40 | 9.00k | ptr: self.ptr.cast(), |
41 | 9.00k | } |
42 | 9.00k | } <anyhow::ptr::Own<anyhow::error::ErrorImpl<rhai::types::parse_error::ParseError>>>::cast::<anyhow::error::ErrorImpl> Line | Count | Source | 38 | 4.50k | pub fn cast<U: CastTo>(self) -> Own<U::Target> { | 39 | 4.50k | Own { | 40 | 4.50k | ptr: self.ptr.cast(), | 41 | 4.50k | } | 42 | 4.50k | } |
Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl>>::cast::<anyhow::error::ErrorImpl<core::mem::manually_drop::ManuallyDrop<rhai::types::parse_error::ParseError>>> <anyhow::ptr::Own<anyhow::error::ErrorImpl>>::cast::<anyhow::error::ErrorImpl<rhai::types::parse_error::ParseError>> Line | Count | Source | 38 | 4.50k | pub fn cast<U: CastTo>(self) -> Own<U::Target> { | 39 | 4.50k | Own { | 40 | 4.50k | ptr: self.ptr.cast(), | 41 | 4.50k | } | 42 | 4.50k | } |
Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl<anyhow::wrapper::MessageError<alloc::string::String>>>>::cast::<anyhow::error::ErrorImpl> Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl<anyhow::wrapper::MessageError<&str>>>>::cast::<anyhow::error::ErrorImpl> Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl<anyhow::wrapper::BoxedError>>>::cast::<anyhow::error::ErrorImpl> Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl>>::cast::<anyhow::error::ErrorImpl<anyhow::wrapper::MessageError<alloc::string::String>>> Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl>>::cast::<anyhow::error::ErrorImpl<anyhow::wrapper::MessageError<&str>>> Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl>>::cast::<anyhow::error::ErrorImpl<core::mem::manually_drop::ManuallyDrop<alloc::boxed::Box<dyn core::error::Error + core::marker::Send + core::marker::Sync>>>> Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl>>::cast::<anyhow::error::ErrorImpl<core::mem::manually_drop::ManuallyDrop<alloc::string::String>>> Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl>>::cast::<anyhow::error::ErrorImpl<core::mem::manually_drop::ManuallyDrop<&str>>> Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl>>::cast::<anyhow::error::ErrorImpl<anyhow::wrapper::BoxedError>> |
43 | | |
44 | 4.50k | pub unsafe fn boxed(self) -> Box<T> { |
45 | 4.50k | unsafe { Box::from_raw(self.ptr.as_ptr()) } |
46 | 4.50k | } Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl<core::mem::manually_drop::ManuallyDrop<rhai::types::parse_error::ParseError>>>>::boxed <anyhow::ptr::Own<anyhow::error::ErrorImpl<rhai::types::parse_error::ParseError>>>::boxed Line | Count | Source | 44 | 4.50k | pub unsafe fn boxed(self) -> Box<T> { | 45 | 4.50k | unsafe { Box::from_raw(self.ptr.as_ptr()) } | 46 | 4.50k | } |
Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl<anyhow::wrapper::MessageError<alloc::string::String>>>>::boxed Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl<anyhow::wrapper::MessageError<&str>>>>::boxed Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl<core::mem::manually_drop::ManuallyDrop<alloc::boxed::Box<dyn core::error::Error + core::marker::Send + core::marker::Sync>>>>>::boxed Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl<core::mem::manually_drop::ManuallyDrop<alloc::string::String>>>>::boxed Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl<core::mem::manually_drop::ManuallyDrop<&str>>>>::boxed Unexecuted instantiation: <anyhow::ptr::Own<anyhow::error::ErrorImpl<anyhow::wrapper::BoxedError>>>::boxed |
47 | | |
48 | 4.50k | pub fn by_ref(&self) -> Ref<T> { |
49 | 4.50k | Ref { |
50 | 4.50k | ptr: self.ptr, |
51 | 4.50k | lifetime: PhantomData, |
52 | 4.50k | } |
53 | 4.50k | } |
54 | | |
55 | 0 | pub fn by_mut(&mut self) -> Mut<T> { |
56 | 0 | Mut { |
57 | 0 | ptr: self.ptr, |
58 | 0 | lifetime: PhantomData, |
59 | 0 | } |
60 | 0 | } |
61 | | } |
62 | | |
63 | | #[repr(transparent)] |
64 | | pub struct Ref<'a, T> |
65 | | where |
66 | | T: ?Sized, |
67 | | { |
68 | | pub ptr: NonNull<T>, |
69 | | lifetime: PhantomData<&'a T>, |
70 | | } |
71 | | |
72 | | impl<'a, T> Copy for Ref<'a, T> where T: ?Sized {} |
73 | | |
74 | | impl<'a, T> Clone for Ref<'a, T> |
75 | | where |
76 | | T: ?Sized, |
77 | | { |
78 | 0 | fn clone(&self) -> Self { |
79 | 0 | *self |
80 | 0 | } |
81 | | } |
82 | | |
83 | | impl<'a, T> Ref<'a, T> |
84 | | where |
85 | | T: ?Sized, |
86 | | { |
87 | 0 | pub fn new(ptr: &'a T) -> Self { |
88 | 0 | Ref { |
89 | 0 | ptr: NonNull::from(ptr), |
90 | 0 | lifetime: PhantomData, |
91 | 0 | } |
92 | 0 | } Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl<rhai::types::parse_error::ParseError>>>::new Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl<anyhow::wrapper::MessageError<alloc::string::String>>>>::new Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl<anyhow::wrapper::MessageError<&str>>>>::new Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl<anyhow::wrapper::BoxedError>>>::new |
93 | | |
94 | | #[cfg(not(anyhow_no_ptr_addr_of))] |
95 | 4.50k | pub fn from_raw(ptr: NonNull<T>) -> Self { |
96 | 4.50k | Ref { |
97 | 4.50k | ptr, |
98 | 4.50k | lifetime: PhantomData, |
99 | 4.50k | } |
100 | 4.50k | } Unexecuted instantiation: <anyhow::ptr::Ref<rhai::types::parse_error::ParseError>>::from_raw <anyhow::ptr::Ref<dyn core::error::Error + core::marker::Send + core::marker::Sync>>::from_raw Line | Count | Source | 95 | 4.50k | pub fn from_raw(ptr: NonNull<T>) -> Self { | 96 | 4.50k | Ref { | 97 | 4.50k | ptr, | 98 | 4.50k | lifetime: PhantomData, | 99 | 4.50k | } | 100 | 4.50k | } |
Unexecuted instantiation: <anyhow::ptr::Ref<alloc::boxed::Box<dyn core::error::Error + core::marker::Send + core::marker::Sync>>>::from_raw Unexecuted instantiation: <anyhow::ptr::Ref<alloc::string::String>>::from_raw Unexecuted instantiation: <anyhow::ptr::Ref<&str>>::from_raw |
101 | | |
102 | 4.50k | pub fn cast<U: CastTo>(self) -> Ref<'a, U::Target> { |
103 | 4.50k | Ref { |
104 | 4.50k | ptr: self.ptr.cast(), |
105 | 4.50k | lifetime: PhantomData, |
106 | 4.50k | } |
107 | 4.50k | } Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl<rhai::types::parse_error::ParseError>>>::cast::<anyhow::error::ErrorImpl> <anyhow::ptr::Ref<anyhow::error::ErrorImpl>>::cast::<anyhow::error::ErrorImpl<rhai::types::parse_error::ParseError>> Line | Count | Source | 102 | 4.50k | pub fn cast<U: CastTo>(self) -> Ref<'a, U::Target> { | 103 | 4.50k | Ref { | 104 | 4.50k | ptr: self.ptr.cast(), | 105 | 4.50k | lifetime: PhantomData, | 106 | 4.50k | } | 107 | 4.50k | } |
Unexecuted instantiation: <anyhow::ptr::Ref<rhai::types::parse_error::ParseError>>::cast::<()> Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl<anyhow::wrapper::MessageError<alloc::string::String>>>>::cast::<anyhow::error::ErrorImpl> Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl<anyhow::wrapper::MessageError<&str>>>>::cast::<anyhow::error::ErrorImpl> Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl<anyhow::wrapper::BoxedError>>>::cast::<anyhow::error::ErrorImpl> Unexecuted instantiation: <anyhow::ptr::Ref<alloc::boxed::Box<dyn core::error::Error + core::marker::Send + core::marker::Sync>>>::cast::<()> Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl>>::cast::<anyhow::error::ErrorImpl<anyhow::wrapper::MessageError<alloc::string::String>>> Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl>>::cast::<anyhow::error::ErrorImpl<anyhow::wrapper::MessageError<&str>>> Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl>>::cast::<anyhow::error::ErrorImpl<alloc::boxed::Box<dyn core::error::Error + core::marker::Send + core::marker::Sync>>> Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl>>::cast::<anyhow::error::ErrorImpl<anyhow::wrapper::BoxedError>> Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl>>::cast::<anyhow::error::ErrorImpl<alloc::string::String>> Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl>>::cast::<anyhow::error::ErrorImpl<&str>> Unexecuted instantiation: <anyhow::ptr::Ref<alloc::string::String>>::cast::<()> Unexecuted instantiation: <anyhow::ptr::Ref<&str>>::cast::<()> |
108 | | |
109 | | #[cfg(not(anyhow_no_ptr_addr_of))] |
110 | 0 | pub fn by_mut(self) -> Mut<'a, T> { |
111 | 0 | Mut { |
112 | 0 | ptr: self.ptr, |
113 | 0 | lifetime: PhantomData, |
114 | 0 | } |
115 | 0 | } |
116 | | |
117 | | #[cfg(not(anyhow_no_ptr_addr_of))] |
118 | 4.50k | pub fn as_ptr(self) -> *const T { |
119 | 4.50k | self.ptr.as_ptr() as *const T |
120 | 4.50k | } <anyhow::ptr::Ref<anyhow::error::ErrorImpl<rhai::types::parse_error::ParseError>>>::as_ptr Line | Count | Source | 118 | 4.50k | pub fn as_ptr(self) -> *const T { | 119 | 4.50k | self.ptr.as_ptr() as *const T | 120 | 4.50k | } |
Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl<anyhow::wrapper::MessageError<alloc::string::String>>>>::as_ptr Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl<anyhow::wrapper::MessageError<&str>>>>::as_ptr Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl<alloc::boxed::Box<dyn core::error::Error + core::marker::Send + core::marker::Sync>>>>::as_ptr Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl<anyhow::wrapper::BoxedError>>>::as_ptr Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl<alloc::string::String>>>::as_ptr Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl<&str>>>::as_ptr |
121 | | |
122 | 4.50k | pub unsafe fn deref(self) -> &'a T { |
123 | 4.50k | unsafe { &*self.ptr.as_ptr() } |
124 | 4.50k | } <anyhow::ptr::Ref<dyn core::error::Error + core::marker::Send + core::marker::Sync>>::deref Line | Count | Source | 122 | 4.50k | pub unsafe fn deref(self) -> &'a T { | 123 | 4.50k | unsafe { &*self.ptr.as_ptr() } | 124 | 4.50k | } |
Unexecuted instantiation: <anyhow::ptr::Ref<anyhow::error::ErrorImpl>>::deref |
125 | | } |
126 | | |
127 | | #[repr(transparent)] |
128 | | pub struct Mut<'a, T> |
129 | | where |
130 | | T: ?Sized, |
131 | | { |
132 | | pub ptr: NonNull<T>, |
133 | | lifetime: PhantomData<&'a mut T>, |
134 | | } |
135 | | |
136 | | impl<'a, T> Copy for Mut<'a, T> where T: ?Sized {} |
137 | | |
138 | | impl<'a, T> Clone for Mut<'a, T> |
139 | | where |
140 | | T: ?Sized, |
141 | | { |
142 | 0 | fn clone(&self) -> Self { |
143 | 0 | *self |
144 | 0 | } |
145 | | } |
146 | | |
147 | | impl<'a, T> Mut<'a, T> |
148 | | where |
149 | | T: ?Sized, |
150 | | { |
151 | | #[cfg(anyhow_no_ptr_addr_of)] |
152 | | pub fn new(ptr: &'a mut T) -> Self { |
153 | | Mut { |
154 | | ptr: NonNull::from(ptr), |
155 | | lifetime: PhantomData, |
156 | | } |
157 | | } |
158 | | |
159 | 0 | pub fn cast<U: CastTo>(self) -> Mut<'a, U::Target> { |
160 | 0 | Mut { |
161 | 0 | ptr: self.ptr.cast(), |
162 | 0 | lifetime: PhantomData, |
163 | 0 | } |
164 | 0 | } |
165 | | |
166 | | #[cfg(not(anyhow_no_ptr_addr_of))] |
167 | 0 | pub fn by_ref(self) -> Ref<'a, T> { |
168 | 0 | Ref { |
169 | 0 | ptr: self.ptr, |
170 | 0 | lifetime: PhantomData, |
171 | 0 | } |
172 | 0 | } |
173 | | |
174 | 0 | pub fn extend<'b>(self) -> Mut<'b, T> { |
175 | 0 | Mut { |
176 | 0 | ptr: self.ptr, |
177 | 0 | lifetime: PhantomData, |
178 | 0 | } |
179 | 0 | } |
180 | | |
181 | 0 | pub unsafe fn deref_mut(self) -> &'a mut T { |
182 | 0 | unsafe { &mut *self.ptr.as_ptr() } |
183 | 0 | } |
184 | | } |
185 | | |
186 | | impl<'a, T> Mut<'a, T> { |
187 | 0 | pub unsafe fn read(self) -> T { |
188 | 0 | unsafe { self.ptr.as_ptr().read() } |
189 | 0 | } |
190 | | } |
191 | | |
192 | | // Force turbofish on all calls of `.cast::<U>()`. |
193 | | pub trait CastTo { |
194 | | type Target; |
195 | | } |
196 | | |
197 | | impl<T> CastTo for T { |
198 | | type Target = T; |
199 | | } |