/home/runner/work/pinned-init/pinned-init/src/lib.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // SPDX-License-Identifier: Apache-2.0 OR MIT |
2 | | |
3 | | //! Library to safely and fallibly initialize pinned `struct`s using in-place constructors. |
4 | | //! |
5 | | //! It also allows in-place initialization of big `struct`s that would otherwise produce a stack |
6 | | //! overflow. |
7 | | //! |
8 | | //! This library's main use-case is in [Rust-for-Linux]. Although this version can be used |
9 | | //! standalone. |
10 | | //! |
11 | | //! There are cases when you want to in-place initialize a struct. For example when it is very big |
12 | | //! and moving it from the stack is not an option, because it is bigger than the stack itself. |
13 | | //! Another reason would be that you need the address of the object to initialize it. This stands |
14 | | //! in direct conflict with Rust's normal process of first initializing an object and then moving |
15 | | //! it into it's final memory location. |
16 | | //! |
17 | | //! This library allows you to do in-place initialization safely. |
18 | | //! |
19 | | //! # Nightly only |
20 | | //! |
21 | | //! This library requires unstable features and thus can only be used with a nightly compiler. |
22 | | //! The used features are: |
23 | | //! - `allocator_api` |
24 | | //! - `new_uninit` (only if the `alloc` or `std` features are enabled) |
25 | | //! - `get_mut_unchecked` (only if the `alloc` or `std` features are enabled) |
26 | | //! |
27 | | //! The user will be required to activate these features: |
28 | | //! - `allocator_api` |
29 | | //! |
30 | | //! # Overview |
31 | | //! |
32 | | //! To initialize a `struct` with an in-place constructor you will need two things: |
33 | | //! - an in-place constructor, |
34 | | //! - a memory location that can hold your `struct` (this can be the [stack], an [`Arc<T>`], |
35 | | //! [`Box<T>`] or any other smart pointer that implements [`InPlaceInit`]). |
36 | | //! |
37 | | //! To get an in-place constructor there are generally three options: |
38 | | //! - directly creating an in-place constructor using the [`pin_init!`] macro, |
39 | | //! - a custom function/macro returning an in-place constructor provided by someone else, |
40 | | //! - using the unsafe function [`pin_init_from_closure()`] to manually create an initializer. |
41 | | //! |
42 | | //! Aside from pinned initialization, this library also supports in-place construction without pinning, |
43 | | //! the macros/types/functions are generally named like the pinned variants without the `pin` |
44 | | //! prefix. |
45 | | //! |
46 | | //! # Examples |
47 | | //! |
48 | | //! Throught some examples we will make use of the `CMutex` type which can be found in the examples |
49 | | //! directory of the repository. It is essentially a rebuild of the `mutex` from the Linux kernel |
50 | | //! in userland. So it also uses a wait list and a basic spinlock. Importantly it needs to be |
51 | | //! pinned to be locked and thus is a prime candidate for this library. |
52 | | //! |
53 | | //! ## Using the [`pin_init!`] macro |
54 | | //! |
55 | | //! If you want to use [`PinInit`], then you will have to annotate your `struct` with |
56 | | //! `#[`[`pin_data`]`]`. It is a macro that uses `#[pin]` as a marker for |
57 | | //! [structurally pinned fields]. After doing this, you can then create an in-place constructor via |
58 | | //! [`pin_init!`]. The syntax is almost the same as normal `struct` initializers. The difference is |
59 | | //! that you need to write `<-` instead of `:` for fields that you want to initialize in-place. |
60 | | //! |
61 | | //! ```rust |
62 | | //! # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)] |
63 | | //! # #![feature(allocator_api, no_coverage)] |
64 | | //! use pinned_init::*; |
65 | | //! # use core::pin::Pin; |
66 | | //! # #[path = "../examples/mutex.rs"] mod mutex; use mutex::*; |
67 | | //! #[pin_data] |
68 | | //! struct Foo { |
69 | | //! #[pin] |
70 | | //! a: CMutex<usize>, |
71 | | //! b: u32, |
72 | | //! } |
73 | | //! |
74 | | //! let foo = pin_init!(Foo { |
75 | | //! a <- CMutex::new(42), |
76 | | //! b: 24, |
77 | | //! }); |
78 | | //! # let _ = Box::pin_init(foo); |
79 | | //! ``` |
80 | | //! |
81 | | //! `foo` now is of the type [`impl PinInit<Foo>`]. We can now use any smart pointer that we like |
82 | | //! (or just the stack) to actually initialize a `Foo`: |
83 | | //! |
84 | | //! ```rust |
85 | | //! # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)] |
86 | | //! # #![feature(allocator_api, no_coverage)] |
87 | | //! # #[path = "../examples/mutex.rs"] mod mutex; use mutex::*; |
88 | | //! # use pinned_init::*; |
89 | | //! # use core::pin::Pin; |
90 | | //! # #[pin_data] |
91 | | //! # struct Foo { |
92 | | //! # #[pin] |
93 | | //! # a: CMutex<usize>, |
94 | | //! # b: u32, |
95 | | //! # } |
96 | | //! # let foo = pin_init!(Foo { |
97 | | //! # a <- CMutex::new(42), |
98 | | //! # b: 24, |
99 | | //! # }); |
100 | | //! let foo: Result<Pin<Box<Foo>>, core::alloc::AllocError> = Box::pin_init(foo); |
101 | | //! ``` |
102 | | //! |
103 | | //! For more information see the [`pin_init!`] macro. |
104 | | //! |
105 | | //! ## Using a custom function/macro that returns an initializer |
106 | | //! |
107 | | //! Many types that use this library supply a function/macro that returns an initializer, because |
108 | | //! the above method only works for types where you can access the fields. |
109 | | //! |
110 | | //! ```rust |
111 | | //! # #![feature(allocator_api, no_coverage)] |
112 | | //! # #[path = "../examples/mutex.rs"] mod mutex; use mutex::*; |
113 | | //! # use pinned_init::*; |
114 | | //! # use std::{alloc::AllocError, pin::Pin}; |
115 | | //! let mtx: Result<Pin<Box<CMutex<usize>>>, AllocError> = Box::pin_init(CMutex::new(42)); |
116 | | //! ``` |
117 | | //! |
118 | | //! To declare an init macro/function you just return an [`impl PinInit<T, E>`]: |
119 | | //! |
120 | | //! ```rust |
121 | | //! # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)] |
122 | | //! # #![feature(allocator_api, no_coverage)] |
123 | | //! # use pinned_init::*; |
124 | | //! # #[path = "../examples/mutex.rs"] mod mutex; use mutex::*; |
125 | | //! use core::alloc::AllocError; |
126 | | //! #[pin_data] |
127 | | //! struct DriverData { |
128 | | //! #[pin] |
129 | | //! status: CMutex<i32>, |
130 | | //! buffer: Box<[u8; 1_000_000]>, |
131 | | //! } |
132 | | //! |
133 | | //! struct DriverDataError; |
134 | | //! |
135 | | //! # impl From<core::convert::Infallible> for DriverDataError { |
136 | | //! # fn from(i: core::convert::Infallible) -> Self { match i {} } |
137 | | //! # } |
138 | | //! # impl From<AllocError> for DriverDataError { |
139 | | //! # fn from(_: AllocError) -> Self { Self } |
140 | | //! # } |
141 | | //! # |
142 | | //! impl DriverData { |
143 | | //! fn new() -> impl PinInit<Self, DriverDataError> { |
144 | | //! try_pin_init!(Self { |
145 | | //! status <- CMutex::new(0), |
146 | | //! buffer: Box::init(zeroed())?, |
147 | | //! }? DriverDataError) |
148 | | //! } |
149 | | //! } |
150 | | //! # let _ = Box::pin_init(DriverData::new()); |
151 | | //! ``` |
152 | | //! |
153 | | //! ## Manual creation of an initializer |
154 | | //! |
155 | | //! Often when working with primitives the previous approaches are not sufficient. That is where |
156 | | //! [`pin_init_from_closure()`] comes in. This `unsafe` function allows you to create a |
157 | | //! [`impl PinInit<T, E>`] directly from a closure. Of course you have to ensure that the closure |
158 | | //! actually does the initialization in the correct way. Here are the things to look out for |
159 | | //! (we are calling the parameter to the closure `slot`): |
160 | | //! - when the closure returns `Ok(())`, then it has completed the initialization successfully, so |
161 | | //! `slot` now contains a valid bit pattern for the type `T`, |
162 | | //! - when the closure returns `Err(e)`, then the caller may deallocate the memory at `slot`, so |
163 | | //! you need to take care to clean up anything if your initialization fails mid-way, |
164 | | //! - you may assume that `slot` will stay pinned even after the closure returns until `drop` of |
165 | | //! `slot` gets called. |
166 | | //! |
167 | | //! ```rust |
168 | | //! # #![feature(extern_types)] |
169 | | //! # #![cfg_attr(coverage_nightly, feature(no_coverage))] |
170 | | //! use pinned_init::*; |
171 | | //! use core::{ptr::addr_of_mut, marker::PhantomPinned, cell::UnsafeCell, pin::Pin}; |
172 | | //! mod bindings { |
173 | | //! extern "C" { |
174 | | //! pub type foo; |
175 | | //! pub fn init_foo(ptr: *mut foo); |
176 | | //! pub fn destroy_foo(ptr: *mut foo); |
177 | | //! #[must_use = "you must check the error return code"] |
178 | | //! pub fn enable_foo(ptr: *mut foo, flags: u32) -> i32; |
179 | | //! } |
180 | | //! } |
181 | | //! |
182 | | //! /// # Invariants |
183 | | //! /// |
184 | | //! /// `foo` is always initialized |
185 | | //! #[pin_data(PinnedDrop)] |
186 | | //! pub struct RawFoo { |
187 | | //! #[pin] |
188 | | //! _p: PhantomPinned, |
189 | | //! #[pin] |
190 | | //! foo: UnsafeCell<bindings::foo>, |
191 | | //! } |
192 | | //! |
193 | | //! impl RawFoo { |
194 | | //! # #[cfg_attr(coverage_nightly, no_coverage)] |
195 | | //! pub fn new(flags: u32) -> impl PinInit<Self, i32> { |
196 | | //! // SAFETY: |
197 | | //! // - when the closure returns `Ok(())`, then it has successfully initialized and |
198 | | //! // enabled `foo`, |
199 | | //! // - when it returns `Err(e)`, then it has cleaned up before |
200 | | //! unsafe { |
201 | | //! pin_init_from_closure(move |slot: *mut Self| { |
202 | | //! // `slot` contains uninit memory, avoid creating a reference. |
203 | | //! let foo = addr_of_mut!((*slot).foo); |
204 | | //! |
205 | | //! // Initialize the `foo` |
206 | | //! bindings::init_foo(UnsafeCell::raw_get(foo)); |
207 | | //! |
208 | | //! // Try to enable it. |
209 | | //! let err = bindings::enable_foo(UnsafeCell::raw_get(foo), flags); |
210 | | //! if err != 0 { |
211 | | //! // Enabling has failed, first clean up the foo and then return the error. |
212 | | //! bindings::destroy_foo(UnsafeCell::raw_get(foo)); |
213 | | //! Err(err) |
214 | | //! } else { |
215 | | //! // All fields of `RawFoo` have been initialized, since `_p` is a ZST. |
216 | | //! Ok(()) |
217 | | //! } |
218 | | //! }) |
219 | | //! } |
220 | | //! } |
221 | | //! } |
222 | | //! |
223 | | //! #[pinned_drop] |
224 | | //! impl PinnedDrop for RawFoo { |
225 | | //! # #[cfg_attr(coverage_nightly, no_coverage)] |
226 | | //! fn drop(self: Pin<&mut Self>) { |
227 | | //! // SAFETY: Since `foo` is initialized, destroying is safe. |
228 | | //! unsafe { bindings::destroy_foo(self.foo.get()) }; |
229 | | //! } |
230 | | //! } |
231 | | //! ``` |
232 | | //! |
233 | | //! For more information on how to use [`pin_init_from_closure()`], you can take a look at the |
234 | | //! uses inside the `kernel` crate from the [Rust-for-Linux] project. The `sync` module is a good |
235 | | //! starting point. |
236 | | //! |
237 | | //! [structurally pinned fields]: |
238 | | //! https://doc.rust-lang.org/std/pin/index.html#pinning-is-structural-for-field |
239 | | //! [stack]: crate::stack_pin_init |
240 | | //! [`Arc<T>`]: alloc::sync::Arc |
241 | | //! [`Box<T>`]: alloc::boxed::Box |
242 | | //! [`impl PinInit<Foo>`]: PinInit |
243 | | //! [`impl PinInit<T, E>`]: PinInit |
244 | | //! [`impl Init<T, E>`]: Init |
245 | | //! [`pin_data`]: ::pinned_init_macro::pin_data |
246 | | //! [Rust-for-Linux]: https://rust-for-linux.com/ |
247 | | |
248 | | #![forbid(missing_docs, unsafe_op_in_unsafe_fn)] |
249 | | #![cfg_attr(not(feature = "std"), no_std)] |
250 | | #![feature(allocator_api)] |
251 | | #![cfg_attr(any(feature = "alloc"), feature(new_uninit))] |
252 | | #![cfg_attr(any(feature = "alloc"), feature(get_mut_unchecked))] |
253 | | #![cfg_attr(coverage_nightly, feature(no_coverage))] |
254 | | |
255 | | #[cfg(any(feature = "alloc"))] |
256 | | extern crate alloc; |
257 | | |
258 | | #[cfg(any(feature = "alloc"))] |
259 | | use alloc::{boxed::Box, sync::Arc}; |
260 | | use core::{ |
261 | | alloc::AllocError, |
262 | | convert::Infallible, |
263 | | marker::PhantomData, |
264 | | mem::MaybeUninit, |
265 | | num::*, |
266 | | pin::Pin, |
267 | | ptr::{self, NonNull}, |
268 | | }; |
269 | | |
270 | | #[doc(hidden)] |
271 | | pub mod __internal; |
272 | | #[doc(hidden)] |
273 | | pub mod macros; |
274 | | |
275 | | pub use pinned_init_macro::{pin_data, pinned_drop, Zeroable}; |
276 | | |
277 | | /// Initialize and pin a type directly on the stack. |
278 | | /// |
279 | | /// # Examples |
280 | | /// |
281 | | /// ```rust |
282 | | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)] |
283 | | /// # #![feature(allocator_api, no_coverage)] |
284 | | /// # #[path = "../examples/mutex.rs"] mod mutex; use mutex::*; |
285 | | /// # use pinned_init::*; |
286 | | /// # use core::pin::Pin; |
287 | | /// #[pin_data] |
288 | | /// struct Foo { |
289 | | /// #[pin] |
290 | | /// a: CMutex<usize>, |
291 | | /// b: Bar, |
292 | | /// } |
293 | | /// |
294 | | /// #[pin_data] |
295 | | /// struct Bar { |
296 | | /// x: u32, |
297 | | /// } |
298 | | /// |
299 | | /// stack_pin_init!(let foo = pin_init!(Foo { |
300 | | /// a <- CMutex::new(42), |
301 | | /// b: Bar { |
302 | | /// x: 64, |
303 | | /// }, |
304 | | /// })); |
305 | | /// let foo: Pin<&mut Foo> = foo; |
306 | | /// println!("a: {}", &*foo.a.lock()); |
307 | | /// ``` |
308 | | /// |
309 | | /// # Syntax |
310 | | /// |
311 | | /// A normal `let` binding with optional type annotation. The expression is expected to implement |
312 | | /// [`PinInit`]/[`Init`] with the error type [`Infallible`]. If you want to use a different error |
313 | | /// type, then use [`stack_try_pin_init!`]. |
314 | | #[macro_export] |
315 | | macro_rules! stack_pin_init { |
316 | | (let $var:ident $(: $t:ty)? = $val:expr) => { |
317 | | let val = $val; |
318 | | let mut $var = ::core::pin::pin!($crate::__internal::StackInit$(::<$t>)?::uninit()); |
319 | | let mut $var = match $crate::__internal::StackInit::init($var, val) { |
320 | | Ok(res) => res, |
321 | | Err(x) => { |
322 | | let x: ::core::convert::Infallible = x; |
323 | | match x {} |
324 | | } |
325 | | }; |
326 | | }; |
327 | | } |
328 | | |
329 | | /// Initialize and pin a type directly on the stack. |
330 | | /// |
331 | | /// # Examples |
332 | | /// |
333 | | /// ```rust |
334 | | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)] |
335 | | /// # #![feature(allocator_api, no_coverage)] |
336 | | /// # #[path = "../examples/mutex.rs"] mod mutex; use mutex::*; |
337 | | /// # use pinned_init::*; |
338 | | /// # use core::{alloc::AllocError, pin::Pin, convert::Infallible}; |
339 | | /// # #[derive(Debug)] |
340 | | /// # struct FooError; |
341 | | /// # impl From<AllocError> for FooError { fn from(_: AllocError) -> Self { Self } } |
342 | | /// # impl From<Infallible> for FooError { fn from(_: Infallible) -> Self { Self } } |
343 | | /// #[pin_data] |
344 | | /// struct Foo { |
345 | | /// #[pin] |
346 | | /// a: CMutex<usize>, |
347 | | /// b: Box<Bar>, |
348 | | /// } |
349 | | /// |
350 | | /// struct Bar { |
351 | | /// x: u32, |
352 | | /// } |
353 | | /// |
354 | | /// stack_try_pin_init!(let foo: Foo = try_pin_init!(Foo { |
355 | | /// a <- CMutex::new(42), |
356 | | /// b: Box::try_new(Bar { |
357 | | /// x: 64, |
358 | | /// })?, |
359 | | /// }? FooError)); |
360 | | /// let foo = foo.unwrap(); |
361 | | /// println!("a: {}", &*foo.a.lock()); |
362 | | /// ``` |
363 | | /// |
364 | | /// ```rust |
365 | | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)] |
366 | | /// # #![feature(allocator_api, no_coverage)] |
367 | | /// # #[path = "../examples/mutex.rs"] mod mutex; use mutex::*; |
368 | | /// # use pinned_init::*; |
369 | | /// # use core::{alloc::AllocError, pin::Pin, convert::Infallible}; |
370 | | /// # #[derive(Debug)] |
371 | | /// # struct FooError; |
372 | | /// # impl From<AllocError> for FooError { fn from(_: AllocError) -> Self { Self } } |
373 | | /// # impl From<Infallible> for FooError { fn from(_: Infallible) -> Self { Self } } |
374 | | /// #[pin_data] |
375 | | /// struct Foo { |
376 | | /// #[pin] |
377 | | /// a: CMutex<usize>, |
378 | | /// b: Box<Bar>, |
379 | | /// } |
380 | | /// |
381 | | /// struct Bar { |
382 | | /// x: u32, |
383 | | /// } |
384 | | /// |
385 | | /// stack_try_pin_init!(let foo: Foo =? try_pin_init!(Foo { |
386 | | /// a <- CMutex::new(42), |
387 | | /// b: Box::try_new(Bar { |
388 | | /// x: 64, |
389 | | /// })?, |
390 | | /// }? FooError)); |
391 | | /// println!("a: {}", &*foo.a.lock()); |
392 | | /// # Ok::<_, FooError>(()) |
393 | | /// ``` |
394 | | /// |
395 | | /// # Syntax |
396 | | /// |
397 | | /// A normal `let` binding with optional type annotation. The expression is expected to implement |
398 | | /// [`PinInit`]/[`Init`]. This macro assigns a result to the given variable, adding a `?` after the |
399 | | /// `=` will propagate this error. |
400 | | #[macro_export] |
401 | | macro_rules! stack_try_pin_init { |
402 | | (let $var:ident $(: $t:ty)? = $val:expr) => { |
403 | | let val = $val; |
404 | | let mut $var = ::core::pin::pin!($crate::__internal::StackInit$(::<$t>)?::uninit()); |
405 | | let mut $var = $crate::__internal::StackInit::init($var, val); |
406 | | }; |
407 | | (let $var:ident $(: $t:ty)? =? $val:expr) => { |
408 | | let val = $val; |
409 | | let mut $var = ::core::pin::pin!($crate::__internal::StackInit$(::<$t>)?::uninit()); |
410 | | let mut $var = $crate::__internal::StackInit::init($var, val)?; |
411 | | }; |
412 | | } |
413 | | |
414 | | /// Construct an in-place, pinned initializer for `struct`s. |
415 | | /// |
416 | | /// This macro defaults the error to [`Infallible`]. If you need a different error, then use |
417 | | /// [`try_pin_init!`]. |
418 | | /// |
419 | | /// The syntax is almost identical to that of a normal `struct` initializer: |
420 | | /// |
421 | | /// ```rust |
422 | | /// # #![feature(allocator_api, no_coverage)] |
423 | | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)] |
424 | | /// # use pinned_init::*; |
425 | | /// # use core::pin::Pin; |
426 | | /// #[pin_data] |
427 | | /// struct Foo { |
428 | | /// a: usize, |
429 | | /// b: Bar, |
430 | | /// } |
431 | | /// |
432 | | /// #[pin_data] |
433 | | /// struct Bar { |
434 | | /// x: u32, |
435 | | /// } |
436 | | /// |
437 | | /// # fn demo() -> impl PinInit<Foo> { |
438 | | /// let a = 42; |
439 | | /// |
440 | | /// let initializer = pin_init!(Foo { |
441 | | /// a, |
442 | | /// b: Bar { |
443 | | /// x: 64, |
444 | | /// }, |
445 | | /// }); |
446 | | /// # initializer } |
447 | | /// # Box::pin_init(demo()).unwrap(); |
448 | | /// ``` |
449 | | /// |
450 | | /// Arbitrary Rust expressions can be used to set the value of a variable. |
451 | | /// |
452 | | /// The fields are initialized in the order that they appear in the initializer. So it is possible |
453 | | /// to read already initialized fields using raw pointers. |
454 | | /// |
455 | | /// IMPORTANT: You are not allowed to create references to fields of the struct inside of the |
456 | | /// initializer. |
457 | | /// |
458 | | /// # Init-functions |
459 | | /// |
460 | | /// When working with this library it is often desired to let others construct your types without |
461 | | /// giving access to all fields. This is where you would normally write a plain function `new` |
462 | | /// that would return a new instance of your type. With this library that is also possible. |
463 | | /// However, there are a few extra things to keep in mind. |
464 | | /// |
465 | | /// To create an initializer function, simply declare it like this: |
466 | | /// |
467 | | /// ```rust |
468 | | /// # #![feature(allocator_api, no_coverage)] |
469 | | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)] |
470 | | /// # use pinned_init::*; |
471 | | /// # use core::pin::Pin; |
472 | | /// # #[pin_data] |
473 | | /// # struct Foo { |
474 | | /// # a: usize, |
475 | | /// # b: Bar, |
476 | | /// # } |
477 | | /// # #[pin_data] |
478 | | /// # struct Bar { |
479 | | /// # x: u32, |
480 | | /// # } |
481 | | /// impl Foo { |
482 | | /// fn new() -> impl PinInit<Self> { |
483 | | /// pin_init!(Self { |
484 | | /// a: 42, |
485 | | /// b: Bar { |
486 | | /// x: 64, |
487 | | /// }, |
488 | | /// }) |
489 | | /// } |
490 | | /// } |
491 | | /// # let _ = Box::pin_init(Foo::new()); |
492 | | /// ``` |
493 | | /// |
494 | | /// Users of `Foo` can now create it like this: |
495 | | /// |
496 | | /// ```rust |
497 | | /// # #![feature(allocator_api, no_coverage)] |
498 | | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)] |
499 | | /// # use pinned_init::*; |
500 | | /// # use core::pin::Pin; |
501 | | /// # #[pin_data] |
502 | | /// # struct Foo { |
503 | | /// # a: usize, |
504 | | /// # b: Bar, |
505 | | /// # } |
506 | | /// # #[pin_data] |
507 | | /// # struct Bar { |
508 | | /// # x: u32, |
509 | | /// # } |
510 | | /// # impl Foo { |
511 | | /// # fn new() -> impl PinInit<Self> { |
512 | | /// # pin_init!(Self { |
513 | | /// # a: 42, |
514 | | /// # b: Bar { |
515 | | /// # x: 64, |
516 | | /// # }, |
517 | | /// # }) |
518 | | /// # } |
519 | | /// # } |
520 | | /// let foo = Box::pin_init(Foo::new()); |
521 | | /// ``` |
522 | | /// |
523 | | /// They can also easily embed it into their own `struct`s: |
524 | | /// |
525 | | /// ```rust |
526 | | /// # #![feature(allocator_api, no_coverage)] |
527 | | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)] |
528 | | /// # use pinned_init::*; |
529 | | /// # use core::pin::Pin; |
530 | | /// # #[pin_data] |
531 | | /// # struct Foo { |
532 | | /// # a: usize, |
533 | | /// # b: Bar, |
534 | | /// # } |
535 | | /// # #[pin_data] |
536 | | /// # struct Bar { |
537 | | /// # x: u32, |
538 | | /// # } |
539 | | /// # impl Foo { |
540 | | /// # fn new() -> impl PinInit<Self> { |
541 | | /// # pin_init!(Self { |
542 | | /// # a: 42, |
543 | | /// # b: Bar { |
544 | | /// # x: 64, |
545 | | /// # }, |
546 | | /// # }) |
547 | | /// # } |
548 | | /// # } |
549 | | /// #[pin_data] |
550 | | /// struct FooContainer { |
551 | | /// #[pin] |
552 | | /// foo1: Foo, |
553 | | /// #[pin] |
554 | | /// foo2: Foo, |
555 | | /// other: u32, |
556 | | /// } |
557 | | /// |
558 | | /// impl FooContainer { |
559 | | /// fn new(other: u32) -> impl PinInit<Self> { |
560 | | /// pin_init!(Self { |
561 | | /// foo1 <- Foo::new(), |
562 | | /// foo2 <- Foo::new(), |
563 | | /// other, |
564 | | /// }) |
565 | | /// } |
566 | | /// } |
567 | | /// # let _ = Box::pin_init(FooContainer::new(0)); |
568 | | /// ``` |
569 | | /// |
570 | | /// Here we see that when using `pin_init!` with `PinInit`, one needs to write `<-` instead of `:`. |
571 | | /// This signifies that the given field is initialized in-place. As with `struct` initializers, just |
572 | | /// writing the field (in this case `other`) without `:` or `<-` means `other: other,`. |
573 | | /// |
574 | | /// # Syntax |
575 | | /// |
576 | | /// As already mentioned in the examples above, inside of `pin_init!` a `struct` initializer with |
577 | | /// the following modifications is expected: |
578 | | /// - Fields that you want to initialize in-place have to use `<-` instead of `:`. |
579 | | /// - In front of the initializer you can write `&this in` to have access to a [`NonNull<Self>`] |
580 | | /// pointer named `this` inside of the initializer. |
581 | | /// - Using struct update syntax one can place `..Zeroable::zeroed()` at the very end of the |
582 | | /// struct, this initializes every field with 0 and then runs all initializers specified in the |
583 | | /// body. This can only be done if [`Zeroable`] is implemented for the struct. |
584 | | /// |
585 | | /// For instance: |
586 | | /// |
587 | | /// ```rust |
588 | | /// # #![feature(allocator_api, no_coverage)] |
589 | | /// # use pinned_init::*; |
590 | | /// # use core::{ptr::addr_of_mut, marker::PhantomPinned}; |
591 | | /// #[pin_data] |
592 | | /// struct Buf { |
593 | | /// // `ptr` points into `buf`. |
594 | | /// ptr: *mut u8, |
595 | | /// buf: [u8; 64], |
596 | | /// #[pin] |
597 | | /// pin: PhantomPinned, |
598 | | /// } |
599 | | /// |
600 | | /// let init = pin_init!(&this in Buf { |
601 | | /// buf: [0; 64], |
602 | | /// ptr: unsafe { addr_of_mut!((*this.as_ptr()).buf).cast() }, |
603 | | /// pin: PhantomPinned, |
604 | | /// }); |
605 | | /// # let _ = Box::pin_init(init); |
606 | | /// ``` |
607 | | /// |
608 | | /// [`NonNull<Self>`]: core::ptr::NonNull |
609 | | // For a detailed example of how this macro works, see the module documentation of the hidden |
610 | | // module `__internal` inside of `__internal.rs`. |
611 | | #[macro_export] |
612 | | macro_rules! pin_init { |
613 | | ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? { |
614 | | $($fields:tt)* |
615 | | }) => { |
616 | | $crate::__init_internal!( |
617 | | @this($($this)?), |
618 | | @typ($t $(::<$($generics),*>)?), |
619 | | @fields($($fields)*), |
620 | | @error(::core::convert::Infallible), |
621 | | @data(PinData, use_data), |
622 | | @has_data(HasPinData, __pin_data), |
623 | | @construct_closure(pin_init_from_closure), |
624 | | @munch_fields($($fields)*), |
625 | | ) |
626 | | }; |
627 | | } |
628 | | |
629 | | /// Construct an in-place, fallible pinned initializer for `struct`s. |
630 | | /// |
631 | | /// If the initialization can complete without error (or [`Infallible`]), then use [`pin_init!`]. |
632 | | /// |
633 | | /// You can use the `?` operator or use `return Err(err)` inside the initializer to stop |
634 | | /// initialization and return the error. |
635 | | /// |
636 | | /// IMPORTANT: if you have `unsafe` code inside of the initializer you have to ensure that when |
637 | | /// initialization fails, the memory can be safely deallocated without any further modifications. |
638 | | /// |
639 | | /// This macro defaults the error to [`AllocError`]. |
640 | | /// |
641 | | /// The syntax is identical to [`pin_init!`] with the following exception: you can append `? $type` |
642 | | /// after the `struct` initializer to specify the error type you want to use. |
643 | | /// |
644 | | /// # Examples |
645 | | /// |
646 | | /// ```rust |
647 | | /// # #![feature(allocator_api, new_uninit, no_coverage)] |
648 | | /// # use core::alloc::AllocError; |
649 | | /// use pinned_init::*; |
650 | | /// #[pin_data] |
651 | | /// struct BigBuf { |
652 | | /// big: Box<[u8; 1024 * 1024 * 1024]>, |
653 | | /// small: [u8; 1024 * 1024], |
654 | | /// ptr: *mut u8, |
655 | | /// } |
656 | | /// |
657 | | /// impl BigBuf { |
658 | | /// fn new() -> impl PinInit<Self, AllocError> { |
659 | | /// try_pin_init!(Self { |
660 | | /// big: Box::init(zeroed())?, |
661 | | /// small: [0; 1024 * 1024], |
662 | | /// ptr: core::ptr::null_mut(), |
663 | | /// }) |
664 | | /// } |
665 | | /// } |
666 | | /// # let _ = Box::pin_init(BigBuf::new()); |
667 | | /// ``` |
668 | | // For a detailed example of how this macro works, see the module documentation of the hidden |
669 | | // module `__internal` inside of `__internal.rs`. |
670 | | #[macro_export] |
671 | | macro_rules! try_pin_init { |
672 | | ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? { |
673 | | $($fields:tt)* |
674 | | }) => { |
675 | | $crate::__init_internal!( |
676 | | @this($($this)?), |
677 | | @typ($t $(::<$($generics),*>)? ), |
678 | | @fields($($fields)*), |
679 | | @error(::core::alloc::AllocError), |
680 | | @data(PinData, use_data), |
681 | | @has_data(HasPinData, __pin_data), |
682 | | @construct_closure(pin_init_from_closure), |
683 | | @munch_fields($($fields)*), |
684 | | ) |
685 | | }; |
686 | | ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? { |
687 | | $($fields:tt)* |
688 | | }? $err:ty) => { |
689 | | $crate::__init_internal!( |
690 | | @this($($this)?), |
691 | | @typ($t $(::<$($generics),*>)? ), |
692 | | @fields($($fields)*), |
693 | | @error($err), |
694 | | @data(PinData, use_data), |
695 | | @has_data(HasPinData, __pin_data), |
696 | | @construct_closure(pin_init_from_closure), |
697 | | @munch_fields($($fields)*), |
698 | | ) |
699 | | }; |
700 | | } |
701 | | |
702 | | /// Construct an in-place initializer for `struct`s. |
703 | | /// |
704 | | /// This macro defaults the error to [`Infallible`]. If you need a different error, then use |
705 | | /// [`try_init!`]. |
706 | | /// |
707 | | /// The syntax is identical to [`pin_init!`] and its safety caveats also apply: |
708 | | /// - `unsafe` code must guarantee either full initialization or return an error and allow |
709 | | /// deallocation of the memory. |
710 | | /// - the fields are initialized in the order given in the initializer. |
711 | | /// - no references to fields are allowed to be created inside of the initializer. |
712 | | /// |
713 | | /// This initializer is for initializing data in-place that might later be moved. If you want to |
714 | | /// pin-initialize, use [`pin_init!`]. |
715 | | /// # Examples |
716 | | /// |
717 | | /// ```rust |
718 | | /// # #![feature(allocator_api, no_coverage)] |
719 | | /// # use core::alloc::AllocError; |
720 | | /// use pinned_init::*; |
721 | | /// struct BigBuf { |
722 | | /// big: Box<[u8; 1024 * 1024 * 1024]>, |
723 | | /// small: [u8; 1024 * 1024], |
724 | | /// } |
725 | | /// |
726 | | /// impl BigBuf { |
727 | | /// fn new() -> impl Init<Self, AllocError> { |
728 | | /// try_init!(Self { |
729 | | /// small <- zeroed(), |
730 | | /// big: Box::init(zeroed())?, |
731 | | /// }? AllocError) |
732 | | /// } |
733 | | /// } |
734 | | /// # let _ = Box::init(BigBuf::new()); |
735 | | /// ``` |
736 | | // For a detailed example of how this macro works, see the module documentation of the hidden |
737 | | // module `__internal` inside of `__internal.rs`. |
738 | | #[macro_export] |
739 | | macro_rules! init { |
740 | | ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? { |
741 | | $($fields:tt)* |
742 | | }) => { |
743 | | $crate::__init_internal!( |
744 | | @this($($this)?), |
745 | | @typ($t $(::<$($generics),*>)?), |
746 | | @fields($($fields)*), |
747 | | @error(::core::convert::Infallible), |
748 | | @data(InitData, /*no use_data*/), |
749 | | @has_data(HasInitData, __init_data), |
750 | | @construct_closure(init_from_closure), |
751 | | @munch_fields($($fields)*), |
752 | | ) |
753 | | } |
754 | | } |
755 | | |
756 | | /// Construct an in-place fallible initializer for `struct`s. |
757 | | /// |
758 | | /// This macro defaults the error to [`AllocError`]. If you need [`Infallible`], then use |
759 | | /// [`init!`]. |
760 | | /// |
761 | | /// The syntax is identical to [`try_pin_init!`]. If you want to specify a custom error, |
762 | | /// append `? $type` after the `struct` initializer. |
763 | | /// The safety caveats from [`try_pin_init!`] also apply: |
764 | | /// - `unsafe` code must guarantee either full initialization or return an error and allow |
765 | | /// deallocation of the memory. |
766 | | /// - the fields are initialized in the order given in the initializer. |
767 | | /// - no references to fields are allowed to be created inside of the initializer. |
768 | | /// |
769 | | /// # Examples |
770 | | /// |
771 | | /// ```rust |
772 | | /// # #![feature(allocator_api, no_coverage)] |
773 | | /// # use core::alloc::AllocError; |
774 | | /// use pinned_init::*; |
775 | | /// struct BigBuf { |
776 | | /// big: Box<[u8; 1024 * 1024 * 1024]>, |
777 | | /// small: [u8; 1024 * 1024], |
778 | | /// } |
779 | | /// |
780 | | /// impl BigBuf { |
781 | | /// fn new() -> impl Init<Self, AllocError> { |
782 | | /// try_init!(Self { |
783 | | /// big: Box::init(zeroed())?, |
784 | | /// small: [0; 1024 * 1024], |
785 | | /// }? AllocError) |
786 | | /// } |
787 | | /// } |
788 | | /// # let _ = Box::init(BigBuf::new()); |
789 | | /// ``` |
790 | | // For a detailed example of how this macro works, see the module documentation of the hidden |
791 | | // module `__internal` inside of `__internal.rs`. |
792 | | #[macro_export] |
793 | | macro_rules! try_init { |
794 | | ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? { |
795 | | $($fields:tt)* |
796 | | }) => { |
797 | | $crate::__init_internal!( |
798 | | @this($($this)?), |
799 | | @typ($t $(::<$($generics),*>)?), |
800 | | @fields($($fields)*), |
801 | | @error(::core::alloc::AllocError), |
802 | | @data(InitData, /*no use_data*/), |
803 | | @has_data(HasInitData, __init_data), |
804 | | @construct_closure(init_from_closure), |
805 | | @munch_fields($($fields)*), |
806 | | ) |
807 | | }; |
808 | | ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? { |
809 | | $($fields:tt)* |
810 | | }? $err:ty) => { |
811 | | $crate::__init_internal!( |
812 | | @this($($this)?), |
813 | | @typ($t $(::<$($generics),*>)?), |
814 | | @fields($($fields)*), |
815 | | @error($err), |
816 | | @data(InitData, /*no use_data*/), |
817 | | @has_data(HasInitData, __init_data), |
818 | | @construct_closure(init_from_closure), |
819 | | @munch_fields($($fields)*), |
820 | | ) |
821 | | }; |
822 | | } |
823 | | |
824 | | /// A pin-initializer for the type `T`. |
825 | | /// |
826 | | /// To use this initializer, you will need a suitable memory location that can hold a `T`. This can |
827 | | /// be [`Box<T>`], [`Arc<T>`] or even the stack (see [`stack_pin_init!`]). Use the |
828 | | /// [`InPlaceInit::pin_init`] function of a smart pointer like [`Arc<T>`] on this. |
829 | | /// |
830 | | /// Also see the [module description](self). |
831 | | /// |
832 | | /// # Safety |
833 | | /// |
834 | | /// When implementing this type you will need to take great care. Also there are probably very few |
835 | | /// cases where a manual implementation is necessary. Use [`pin_init_from_closure`] where possible. |
836 | | /// |
837 | | /// The [`PinInit::__pinned_init`] function |
838 | | /// - returns `Ok(())` if it initialized every field of `slot`, |
839 | | /// - returns `Err(err)` if it encountered an error and then cleaned `slot`, this means: |
840 | | /// - `slot` can be deallocated without UB occurring, |
841 | | /// - `slot` does not need to be dropped, |
842 | | /// - `slot` is not partially initialized. |
843 | | /// - while constructing the `T` at `slot` it upholds the pinning invariants of `T`. |
844 | | /// |
845 | | /// [`Arc<T>`]: alloc::sync::Arc |
846 | | #[must_use = "An initializer must be used in order to create its value."] |
847 | | pub unsafe trait PinInit<T: ?Sized, E = Infallible>: Sized { |
848 | | /// Initializes `slot`. |
849 | | /// |
850 | | /// # Safety |
851 | | /// |
852 | | /// - `slot` is a valid pointer to uninitialized memory. |
853 | | /// - the caller does not touch `slot` when `Err` is returned, they are only permitted to |
854 | | /// deallocate. |
855 | | /// - `slot` will not move until it is dropped, i.e. it will be pinned. |
856 | | unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E>; |
857 | | |
858 | | /// First initializes the value using `self` then calls the function `f` with the initialized |
859 | | /// value. |
860 | | /// |
861 | | /// # Examples |
862 | | /// |
863 | | /// ```rust |
864 | | /// # #![allow(clippy::disallowed_names)] |
865 | | /// use pinned_init::*; |
866 | | /// use core::{mem::MaybeUninit, pin::Pin, convert::Infallible}; |
867 | | /// #[repr(C)] |
868 | | /// struct RawFoo([u8; 16]); |
869 | | /// extern { |
870 | | /// fn init_foo(_: *mut RawFoo); |
871 | | /// } |
872 | | /// |
873 | | /// #[pin_data] |
874 | | /// struct Foo { |
875 | | /// #[pin] |
876 | | /// raw: MaybeUninit<RawFoo>, |
877 | | /// } |
878 | | /// |
879 | | /// impl Foo { |
880 | | /// fn setup(self: Pin<&mut Self>) { |
881 | | /// println!("Setting up foo"); |
882 | | /// } |
883 | | /// } |
884 | | /// |
885 | | /// let foo = pin_init!(Foo { |
886 | | /// raw <- unsafe { |
887 | | /// pin_init_from_closure(|slot: *mut MaybeUninit<RawFoo>| { |
888 | | /// init_foo(slot.cast::<RawFoo>()); |
889 | | /// Ok::<_, Infallible>(()) |
890 | | /// }) |
891 | | /// }, |
892 | | /// }).pin_chain(|foo| { |
893 | | /// foo.setup(); |
894 | | /// Ok(()) |
895 | | /// }); |
896 | | /// ``` |
897 | 0 | fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E> |
898 | 0 | where |
899 | 0 | F: FnOnce(Pin<&mut T>) -> Result<(), E>, |
900 | 0 | { |
901 | 0 | ChainPinInit(self, f, PhantomData) |
902 | 0 | } Unexecuted instantiation: <_ as pinned_init::PinInit<_, _>>::pin_chain::<_> Unexecuted instantiation: <_ as pinned_init::PinInit<_, _>>::pin_chain::<_> |
903 | | } |
904 | | |
905 | | /// An initializer returned by [`PinInit::pin_chain`]. |
906 | | pub struct ChainPinInit<I, F, T: ?Sized, E>(I, F, __internal::Invariant<(E, *const T)>); |
907 | | |
908 | | // SAFETY: the `__pinned_init` function is implemented such that it |
909 | | // - returns `Ok(())` on successful initialization, |
910 | | // - returns `Err(err)` on error and in this case `slot` will be dropped. |
911 | | // - considers `slot` pinned. |
912 | | unsafe impl<T: ?Sized, E, I, F> PinInit<T, E> for ChainPinInit<I, F, T, E> |
913 | | where |
914 | | I: PinInit<T, E>, |
915 | | F: FnOnce(Pin<&mut T>) -> Result<(), E>, |
916 | | { |
917 | | unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> { |
918 | | // SAFETY: all requirements fulfilled since this function is `__pinned_init`. |
919 | 0 | unsafe { self.0.__pinned_init(slot)? }; |
920 | | // SAFETY: The above call initialized `slot` and we still have unique access. |
921 | 0 | let val = unsafe { &mut *slot }; |
922 | 0 | // SAFETY: `slot` is considered pinned |
923 | 0 | let val = unsafe { Pin::new_unchecked(val) }; |
924 | 0 | (self.1)(val).map_err(|e| { |
925 | 0 | // SAFETY: `slot` was initialized above. |
926 | 0 | unsafe { core::ptr::drop_in_place(slot) }; |
927 | 0 | e |
928 | 0 | }) Unexecuted instantiation: <pinned_init::ChainPinInit<_, _, _, _> as pinned_init::PinInit<_, _>>::__pinned_init::{closure#0} Unexecuted instantiation: <pinned_init::ChainPinInit<_, _, _, _> as pinned_init::PinInit<_, _>>::__pinned_init::{closure#0} |
929 | 0 | } Unexecuted instantiation: <pinned_init::ChainPinInit<_, _, _, _> as pinned_init::PinInit<_, _>>::__pinned_init Unexecuted instantiation: <pinned_init::ChainPinInit<_, _, _, _> as pinned_init::PinInit<_, _>>::__pinned_init |
930 | | } |
931 | | |
932 | | /// An initializer for `T`. |
933 | | /// |
934 | | /// To use this initializer, you will need a suitable memory location that can hold a `T`. This can |
935 | | /// be [`Box<T>`], [`Arc<T>`] or even the stack (see [`stack_pin_init!`]). Use the |
936 | | /// [`InPlaceInit::init`] function of a smart pointer like [`Arc<T>`] on this. Because |
937 | | /// [`PinInit<T, E>`] is a super trait, you can use every function that takes it as well. |
938 | | /// |
939 | | /// Also see the [module description](self). |
940 | | /// |
941 | | /// # Safety |
942 | | /// |
943 | | /// When implementing this type you will need to take great care. Also there are probably very few |
944 | | /// cases where a manual implementation is necessary. Use [`init_from_closure`] where possible. |
945 | | /// |
946 | | /// The [`Init::__init`] function |
947 | | /// - returns `Ok(())` if it initialized every field of `slot`, |
948 | | /// - returns `Err(err)` if it encountered an error and then cleaned `slot`, this means: |
949 | | /// - `slot` can be deallocated without UB occurring, |
950 | | /// - `slot` does not need to be dropped, |
951 | | /// - `slot` is not partially initialized. |
952 | | /// - while constructing the `T` at `slot` it upholds the pinning invariants of `T`. |
953 | | /// |
954 | | /// The `__pinned_init` function from the supertrait [`PinInit`] needs to execute the exact same |
955 | | /// code as `__init`. |
956 | | /// |
957 | | /// Contrary to its supertype [`PinInit<T, E>`] the caller is allowed to |
958 | | /// move the pointee after initialization. |
959 | | /// |
960 | | /// [`Arc<T>`]: alloc::sync::Arc |
961 | | #[must_use = "An initializer must be used in order to create its value."] |
962 | | pub unsafe trait Init<T: ?Sized, E = Infallible>: PinInit<T, E> { |
963 | | /// Initializes `slot`. |
964 | | /// |
965 | | /// # Safety |
966 | | /// |
967 | | /// - `slot` is a valid pointer to uninitialized memory. |
968 | | /// - the caller does not touch `slot` when `Err` is returned, they are only permitted to |
969 | | /// deallocate. |
970 | | unsafe fn __init(self, slot: *mut T) -> Result<(), E>; |
971 | | |
972 | | /// First initializes the value using `self` then calls the function `f` with the initialized |
973 | | /// value. |
974 | | /// |
975 | | /// # Examples |
976 | | /// |
977 | | /// ```rust |
978 | | /// # #![allow(clippy::disallowed_names)] |
979 | | /// use pinned_init::*; |
980 | | /// use core::convert::Infallible; |
981 | | /// struct Foo { |
982 | | /// buf: [u8; 1_000_000], |
983 | | /// } |
984 | | /// |
985 | | /// impl Foo { |
986 | | /// fn setup(&mut self) { |
987 | | /// println!("Setting up foo"); |
988 | | /// } |
989 | | /// } |
990 | | /// |
991 | | /// let foo = init!(Foo { |
992 | | /// buf <- zeroed::<_, Infallible>() |
993 | | /// }).chain(|foo| { |
994 | | /// foo.setup(); |
995 | | /// Ok(()) |
996 | | /// }); |
997 | | /// ``` |
998 | 0 | fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E> |
999 | 0 | where |
1000 | 0 | F: FnOnce(&mut T) -> Result<(), E>, |
1001 | 0 | { |
1002 | 0 | ChainInit(self, f, PhantomData) |
1003 | 0 | } Unexecuted instantiation: <_ as pinned_init::Init<_, _>>::chain::<_> Unexecuted instantiation: <_ as pinned_init::Init<_, _>>::chain::<_> |
1004 | | } |
1005 | | |
1006 | | /// An initializer returned by [`Init::chain`]. |
1007 | | pub struct ChainInit<I, F, T: ?Sized, E>(I, F, __internal::Invariant<(E, Box<T>)>); |
1008 | | |
1009 | | // SAFETY: the `__init` function is implemented such that it |
1010 | | // - returns `Ok(())` on successful initialization, |
1011 | | // - returns `Err(err)` on error and in this case `slot` will be dropped. |
1012 | | unsafe impl<T: ?Sized, E, I, F> Init<T, E> for ChainInit<I, F, T, E> |
1013 | | where |
1014 | | I: Init<T, E>, |
1015 | | F: FnOnce(&mut T) -> Result<(), E>, |
1016 | | { |
1017 | | unsafe fn __init(self, slot: *mut T) -> Result<(), E> { |
1018 | | // SAFETY: all requirements fulfilled since this function is `__init`. |
1019 | 0 | unsafe { self.0.__pinned_init(slot)? }; |
1020 | | // SAFETY: The above call initialized `slot` and we still have unique access. |
1021 | 0 | (self.1)(unsafe { &mut *slot }).map_err(|e| { |
1022 | 0 | // SAFETY: `slot` was initialized above. |
1023 | 0 | unsafe { core::ptr::drop_in_place(slot) }; |
1024 | 0 | e |
1025 | 0 | }) Unexecuted instantiation: <pinned_init::ChainInit<_, _, _, _> as pinned_init::Init<_, _>>::__init::{closure#0} Unexecuted instantiation: <pinned_init::ChainInit<_, _, _, _> as pinned_init::Init<_, _>>::__init::{closure#0} |
1026 | 0 | } Unexecuted instantiation: <pinned_init::ChainInit<_, _, _, _> as pinned_init::Init<_, _>>::__init Unexecuted instantiation: <pinned_init::ChainInit<_, _, _, _> as pinned_init::Init<_, _>>::__init |
1027 | | } |
1028 | | |
1029 | | // SAFETY: `__pinned_init` behaves exactly the same as `__init`. |
1030 | | unsafe impl<T: ?Sized, E, I, F> PinInit<T, E> for ChainInit<I, F, T, E> |
1031 | | where |
1032 | | I: Init<T, E>, |
1033 | | F: FnOnce(&mut T) -> Result<(), E>, |
1034 | | { |
1035 | 0 | unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> { |
1036 | 0 | // SAFETY: `__init` has less strict requirements compared to `__pinned_init`. |
1037 | 0 | unsafe { self.__init(slot) } |
1038 | 0 | } Unexecuted instantiation: <pinned_init::ChainInit<_, _, _, _> as pinned_init::PinInit<_, _>>::__pinned_init Unexecuted instantiation: <pinned_init::ChainInit<_, _, _, _> as pinned_init::PinInit<_, _>>::__pinned_init |
1039 | | } |
1040 | | |
1041 | | /// Creates a new [`PinInit<T, E>`] from the given closure. |
1042 | | /// |
1043 | | /// # Safety |
1044 | | /// |
1045 | | /// The closure: |
1046 | | /// - returns `Ok(())` if it initialized every field of `slot`, |
1047 | | /// - returns `Err(err)` if it encountered an error and then cleaned `slot`, this means: |
1048 | | /// - `slot` can be deallocated without UB occurring, |
1049 | | /// - `slot` does not need to be dropped, |
1050 | | /// - `slot` is not partially initialized. |
1051 | | /// - may assume that the `slot` does not move if `T: !Unpin`, |
1052 | | /// - while constructing the `T` at `slot` it upholds the pinning invariants of `T`. |
1053 | | #[inline] |
1054 | 81.5k | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( |
1055 | 81.5k | f: impl FnOnce(*mut T) -> Result<(), E>, |
1056 | 81.5k | ) -> impl PinInit<T, E> { |
1057 | 81.5k | __internal::InitClosure(f, PhantomData) |
1058 | 81.5k | } pinned_init::pin_init_from_closure::<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>, core::convert::Infallible, <alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>::new::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<alloc_fail::ring_buf::mutex::CMutex<usize>, core::convert::Infallible, <alloc_fail::ring_buf::mutex::CMutex<usize>>::new<usize>::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<core::cell::UnsafeCell<usize>, core::convert::Infallible, <alloc_fail::ring_buf::mutex::CMutex<usize>>::new<usize>::{closure#0}::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>, core::convert::Infallible, <alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>>::new<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>::new::{closure#1}, alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>, core::convert::Infallible>>::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<alloc_fail::ring_buf::mutex::linked_list::ListHead, core::convert::Infallible, <alloc_fail::ring_buf::mutex::linked_list::ListHead>::insert_next::{closure#1}> Line | Count | Source | 1054 | 4 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 4 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 4 | ) -> impl PinInit<T, E> { | 1057 | 4 | __internal::InitClosure(f, PhantomData) | 1058 | 4 | } |
pinned_init::pin_init_from_closure::<alloc_fail::ring_buf::RingBuffer<u8, 64usize>, core::convert::Infallible, <alloc_fail::ring_buf::RingBuffer<u8, 64usize>>::new::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<alloc_fail::ring_buf::mutex::WaitEntry, core::convert::Infallible, <alloc_fail::ring_buf::mutex::WaitEntry>::insert_new::{closure#1}> Line | Count | Source | 1054 | 9.81k | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 9.81k | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 9.81k | ) -> impl PinInit<T, E> { | 1057 | 9.81k | __internal::InitClosure(f, PhantomData) | 1058 | 9.81k | } |
pinned_init::pin_init_from_closure::<core::cell::UnsafeCell<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>, core::convert::Infallible, <alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>>::new<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>::new::{closure#1}, alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>, core::convert::Infallible>>::{closure#0}::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>, core::convert::Infallible, <alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>>::new::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<alloc_fail::ring_buf::mutex::CMutex<usize>, core::alloc::AllocError, <alloc::sync::Arc<alloc_fail::ring_buf::mutex::CMutex<usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::CMutex<usize>>>::pin_init<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::mutex::CMutex<usize>>::new<usize>::{closure#1}, alloc_fail::ring_buf::mutex::CMutex<usize>, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<alloc_fail::ring_buf::mutex::linked_list::ListHead, core::convert::Infallible, <alloc_fail::ring_buf::mutex::linked_list::ListHead>::insert_prev::{closure#1}> Line | Count | Source | 1054 | 9.81k | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 9.81k | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 9.81k | ) -> impl PinInit<T, E> { | 1057 | 9.81k | __internal::InitClosure(f, PhantomData) | 1058 | 9.81k | } |
pinned_init::pin_init_from_closure::<alloc_fail::ring_buf::mutex::linked_list::ListHead, core::alloc::AllocError, <alloc::boxed::Box<alloc_fail::ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::mutex::linked_list::ListHead>::new::{closure#1}, alloc_fail::ring_buf::mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>, core::alloc::AllocError, <alloc::boxed::Box<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>>>::pin_init<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>>::new::{closure#1}, alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>, core::alloc::AllocError, <alloc::sync::Arc<alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>>>::pin_init<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>>::new<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>::new::{closure#1}, alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>, core::convert::Infallible>>::{closure#1}, alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<alloc_fail::ring_buf::mutex::linked_list::ListHead, core::convert::Infallible, <alloc_fail::ring_buf::mutex::linked_list::ListHead>::new::{closure#1}> Line | Count | Source | 1054 | 3 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 3 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 3 | ) -> impl PinInit<T, E> { | 1057 | 3 | __internal::InitClosure(f, PhantomData) | 1058 | 3 | } |
pinned_init::pin_init_from_closure::<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>, core::alloc::AllocError, <alloc::sync::Arc<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>>::pin_init<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>::new::{closure#1}, alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>, core::convert::Infallible, <alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>::new::{closure#1}> Line | Count | Source | 1054 | 2 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 2 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 2 | ) -> impl PinInit<T, E> { | 1057 | 2 | __internal::InitClosure(f, PhantomData) | 1058 | 2 | } |
pinned_init::pin_init_from_closure::<alloc_fail::ring_buf::mutex::linked_list::ListHead, core::alloc::AllocError, <alloc::boxed::Box<alloc_fail::ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::mutex::linked_list::ListHead>::insert_next::{closure#1}, alloc_fail::ring_buf::mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>, core::alloc::AllocError, <alloc::boxed::Box<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>>::pin_init<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>::new::{closure#1}, alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
Unexecuted instantiation: pinned_init::pin_init_from_closure::<_, _, _> Unexecuted instantiation: pinned_init::pin_init_from_closure::<_, _, _> pinned_init::pin_init_from_closure::<ring_buf::mutex::CMutex<usize>, core::convert::Infallible, <ring_buf::mutex::CMutex<usize>>::new<usize>::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<ring_buf::mutex::linked_list::ListHead, core::alloc::AllocError, <alloc::boxed::Box<ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<ring_buf::mutex::linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<ring_buf::mutex::linked_list::ListHead>::new::{closure#1}, ring_buf::mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<ring_buf::mutex::linked_list::ListHead, core::convert::Infallible, <ring_buf::mutex::linked_list::ListHead>::new::{closure#1}> Line | Count | Source | 1054 | 3 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 3 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 3 | ) -> impl PinInit<T, E> { | 1057 | 3 | __internal::InitClosure(f, PhantomData) | 1058 | 3 | } |
pinned_init::pin_init_from_closure::<ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>, core::convert::Infallible, <ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>>::new<pinned_init::__internal::InitClosure<<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>::new::{closure#1}, ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>, core::convert::Infallible>>::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<ring_buf::RingBuffer<u8, 64usize>, core::convert::Infallible, <ring_buf::RingBuffer<u8, 64usize>>::new::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<core::cell::UnsafeCell<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>, core::convert::Infallible, <ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>>::new<pinned_init::__internal::InitClosure<<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>::new::{closure#1}, ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>, core::convert::Infallible>>::{closure#0}::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<ring_buf::mutex::CMutex<usize>, core::alloc::AllocError, <alloc::sync::Arc<ring_buf::mutex::CMutex<usize>> as pinned_init::InPlaceInit<ring_buf::mutex::CMutex<usize>>>::pin_init<pinned_init::__internal::InitClosure<<ring_buf::mutex::CMutex<usize>>::new<usize>::{closure#1}, ring_buf::mutex::CMutex<usize>, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<ring_buf::mutex::linked_list::ListHead, core::convert::Infallible, <ring_buf::mutex::linked_list::ListHead>::insert_prev::{closure#1}> Line | Count | Source | 1054 | 9.77k | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 9.77k | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 9.77k | ) -> impl PinInit<T, E> { | 1057 | 9.77k | __internal::InitClosure(f, PhantomData) | 1058 | 9.77k | } |
pinned_init::pin_init_from_closure::<ring_buf::mutex::linked_list::ListHead, core::convert::Infallible, <ring_buf::mutex::linked_list::ListHead>::insert_next::{closure#1}> Line | Count | Source | 1054 | 4 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 4 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 4 | ) -> impl PinInit<T, E> { | 1057 | 4 | __internal::InitClosure(f, PhantomData) | 1058 | 4 | } |
pinned_init::pin_init_from_closure::<core::cell::UnsafeCell<usize>, core::convert::Infallible, <ring_buf::mutex::CMutex<usize>>::new<usize>::{closure#0}::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>, core::alloc::AllocError, <alloc::boxed::Box<ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>> as pinned_init::InPlaceInit<ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>>>::pin_init<pinned_init::__internal::InitClosure<<ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>>::new::{closure#1}, ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>, core::alloc::AllocError, <alloc::sync::Arc<ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>> as pinned_init::InPlaceInit<ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>>>::pin_init<pinned_init::__internal::InitClosure<<ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>>::new<pinned_init::__internal::InitClosure<<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>::new::{closure#1}, ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>, core::convert::Infallible>>::{closure#1}, ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>, core::convert::Infallible, <ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>>::new::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<ring_buf::mutex::linked_list::ListHead, core::alloc::AllocError, <alloc::boxed::Box<ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<ring_buf::mutex::linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<ring_buf::mutex::linked_list::ListHead>::insert_next::{closure#1}, ring_buf::mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<ring_buf::mutex::WaitEntry, core::convert::Infallible, <ring_buf::mutex::WaitEntry>::insert_new::{closure#1}> Line | Count | Source | 1054 | 9.77k | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 9.77k | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 9.77k | ) -> impl PinInit<T, E> { | 1057 | 9.77k | __internal::InitClosure(f, PhantomData) | 1058 | 9.77k | } |
pinned_init::pin_init_from_closure::<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>, core::convert::Infallible, <ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>::new::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<linked_list::ListHead, core::alloc::AllocError, <alloc::boxed::Box<linked_list::ListHead> as pinned_init::InPlaceInit<linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<linked_list::ListHead>::insert_next::{closure#1}, linked_list::ListHead, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<linked_list::ListHead, core::alloc::AllocError, <alloc::boxed::Box<linked_list::ListHead> as pinned_init::InPlaceInit<linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<linked_list::ListHead>::new::{closure#1}, linked_list::ListHead, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<linked_list::ListHead, core::convert::Infallible, <linked_list::ListHead>::insert_next::{closure#1}> Line | Count | Source | 1054 | 4 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 4 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 4 | ) -> impl PinInit<T, E> { | 1057 | 4 | __internal::InitClosure(f, PhantomData) | 1058 | 4 | } |
pinned_init::pin_init_from_closure::<linked_list::ListHead, core::convert::Infallible, <linked_list::ListHead>::new::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<mutex::linked_list::ListHead, core::convert::Infallible, <mutex::linked_list::ListHead>::insert_next::{closure#1}> Line | Count | Source | 1054 | 4 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 4 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 4 | ) -> impl PinInit<T, E> { | 1057 | 4 | __internal::InitClosure(f, PhantomData) | 1058 | 4 | } |
pinned_init::pin_init_from_closure::<mutex::linked_list::ListHead, core::convert::Infallible, <mutex::linked_list::ListHead>::insert_prev::{closure#1}> Line | Count | Source | 1054 | 10.5k | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 10.5k | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 10.5k | ) -> impl PinInit<T, E> { | 1057 | 10.5k | __internal::InitClosure(f, PhantomData) | 1058 | 10.5k | } |
pinned_init::pin_init_from_closure::<mutex::WaitEntry, core::convert::Infallible, <mutex::WaitEntry>::insert_new::{closure#1}> Line | Count | Source | 1054 | 10.5k | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 10.5k | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 10.5k | ) -> impl PinInit<T, E> { | 1057 | 10.5k | __internal::InitClosure(f, PhantomData) | 1058 | 10.5k | } |
pinned_init::pin_init_from_closure::<mutex::linked_list::ListHead, core::convert::Infallible, <mutex::linked_list::ListHead>::new::{closure#1}> Line | Count | Source | 1054 | 2 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 2 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 2 | ) -> impl PinInit<T, E> { | 1057 | 2 | __internal::InitClosure(f, PhantomData) | 1058 | 2 | } |
pinned_init::pin_init_from_closure::<mutex::linked_list::ListHead, core::alloc::AllocError, <alloc::boxed::Box<mutex::linked_list::ListHead> as pinned_init::InPlaceInit<mutex::linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<mutex::linked_list::ListHead>::insert_next::{closure#1}, mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<mutex::CMutex<usize>, core::convert::Infallible, <mutex::CMutex<usize>>::new<usize>::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<core::cell::UnsafeCell<usize>, core::convert::Infallible, <mutex::CMutex<usize>>::new<usize>::{closure#0}::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<mutex::CMutex<usize>, core::alloc::AllocError, <alloc::sync::Arc<mutex::CMutex<usize>> as pinned_init::InPlaceInit<mutex::CMutex<usize>>>::pin_init<pinned_init::__internal::InitClosure<<mutex::CMutex<usize>>::new<usize>::{closure#1}, mutex::CMutex<usize>, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<mutex::linked_list::ListHead, core::alloc::AllocError, <alloc::boxed::Box<mutex::linked_list::ListHead> as pinned_init::InPlaceInit<mutex::linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<mutex::linked_list::ListHead>::new::{closure#1}, mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<pthread_mutex::pthread_mtx::PThreadMutex<usize>, pthread_mutex::pthread_mtx::Error, <pthread_mutex::pthread_mtx::PThreadMutex<usize>>::new::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<core::cell::UnsafeCell<libc::unix::linux_like::linux::pthread_mutex_t>, pthread_mutex::pthread_mtx::Error, <pthread_mutex::pthread_mtx::PThreadMutex<_>>::new::init_raw::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<core::cell::UnsafeCell<usize>, core::convert::Infallible, <static_init::mutex::CMutex<usize>>::new<usize>::{closure#0}::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<static_init::mutex::linked_list::ListHead, core::alloc::AllocError, <alloc::boxed::Box<static_init::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<static_init::mutex::linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<static_init::mutex::linked_list::ListHead>::new::{closure#1}, static_init::mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<static_init::mutex::CMutex<usize>, core::convert::Infallible, <static_init::mutex::CMutex<usize>>::new<usize>::{closure#1}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<static_init::mutex::linked_list::ListHead, core::convert::Infallible, <static_init::mutex::linked_list::ListHead>::insert_next::{closure#1}> Line | Count | Source | 1054 | 4 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 4 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 4 | ) -> impl PinInit<T, E> { | 1057 | 4 | __internal::InitClosure(f, PhantomData) | 1058 | 4 | } |
pinned_init::pin_init_from_closure::<static_init::mutex::linked_list::ListHead, core::convert::Infallible, <static_init::mutex::linked_list::ListHead>::insert_prev::{closure#1}> Line | Count | Source | 1054 | 10.5k | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 10.5k | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 10.5k | ) -> impl PinInit<T, E> { | 1057 | 10.5k | __internal::InitClosure(f, PhantomData) | 1058 | 10.5k | } |
pinned_init::pin_init_from_closure::<static_init::mutex::linked_list::ListHead, core::convert::Infallible, <static_init::mutex::linked_list::ListHead>::new::{closure#1}> Line | Count | Source | 1054 | 2 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 2 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 2 | ) -> impl PinInit<T, E> { | 1057 | 2 | __internal::InitClosure(f, PhantomData) | 1058 | 2 | } |
pinned_init::pin_init_from_closure::<static_init::mutex::CMutex<usize>, core::alloc::AllocError, <alloc::sync::Arc<static_init::mutex::CMutex<usize>> as pinned_init::InPlaceInit<static_init::mutex::CMutex<usize>>>::pin_init<pinned_init::__internal::InitClosure<<static_init::mutex::CMutex<usize>>::new<usize>::{closure#1}, static_init::mutex::CMutex<usize>, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<static_init::mutex::linked_list::ListHead, core::alloc::AllocError, <alloc::boxed::Box<static_init::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<static_init::mutex::linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<static_init::mutex::linked_list::ListHead>::insert_next::{closure#1}, static_init::mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1054 | 1 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 1 | ) -> impl PinInit<T, E> { | 1057 | 1 | __internal::InitClosure(f, PhantomData) | 1058 | 1 | } |
pinned_init::pin_init_from_closure::<static_init::mutex::WaitEntry, core::convert::Infallible, <static_init::mutex::WaitEntry>::insert_new::{closure#1}> Line | Count | Source | 1054 | 10.5k | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>( | 1055 | 10.5k | f: impl FnOnce(*mut T) -> Result<(), E>, | 1056 | 10.5k | ) -> impl PinInit<T, E> { | 1057 | 10.5k | __internal::InitClosure(f, PhantomData) | 1058 | 10.5k | } |
|
1059 | | |
1060 | | /// Creates a new [`Init<T, E>`] from the given closure. |
1061 | | /// |
1062 | | /// # Safety |
1063 | | /// |
1064 | | /// The closure: |
1065 | | /// - returns `Ok(())` if it initialized every field of `slot`, |
1066 | | /// - returns `Err(err)` if it encountered an error and then cleaned `slot`, this means: |
1067 | | /// - `slot` can be deallocated without UB occurring, |
1068 | | /// - `slot` does not need to be dropped, |
1069 | | /// - `slot` is not partially initialized. |
1070 | | /// - the `slot` may move after initialization. |
1071 | | /// - while constructing the `T` at `slot` it upholds the pinning invariants of `T`. |
1072 | | #[inline] |
1073 | 686 | pub const unsafe fn init_from_closure<T: ?Sized, E>( |
1074 | 686 | f: impl FnOnce(*mut T) -> Result<(), E>, |
1075 | 686 | ) -> impl Init<T, E> { |
1076 | 686 | __internal::InitClosure(f, PhantomData) |
1077 | 686 | } pinned_init::init_from_closure::<alloc_fail::ring_buf::EvenU64, core::alloc::AllocError, <alloc_fail::ring_buf::EvenU64>::new2::{closure#1}> Line | Count | Source | 1073 | 4 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 4 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 4 | ) -> impl Init<T, E> { | 1076 | 4 | __internal::InitClosure(f, PhantomData) | 1077 | 4 | } |
pinned_init::init_from_closure::<alloc_fail::ring_buf::BigStruct, core::convert::Infallible, alloc_fail::ring_buf::big_struct::{closure#1}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
Unexecuted instantiation: pinned_init::init_from_closure::<[core::mem::maybe_uninit::MaybeUninit<u8>; 1099511627776usize], core::convert::Infallible, <alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>::new::{closure#0}::{closure#1}> pinned_init::init_from_closure::<[u8; 1099511627776usize], core::convert::Infallible, pinned_init::zeroed<[u8; 1099511627776usize], core::convert::Infallible>::{closure#0}> Line | Count | Source | 1073 | 2 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 2 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 2 | ) -> impl Init<T, E> { | 1076 | 2 | __internal::InitClosure(f, PhantomData) | 1077 | 2 | } |
pinned_init::init_from_closure::<alloc_fail::ring_buf::BigStruct, core::convert::Infallible, <alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>::pop_no_stack::{closure#0}> Line | Count | Source | 1073 | 63 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 63 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 63 | ) -> impl Init<T, E> { | 1076 | 63 | __internal::InitClosure(f, PhantomData) | 1077 | 63 | } |
pinned_init::init_from_closure::<alloc_fail::ring_buf::BigStruct, core::convert::Infallible, alloc_fail::ring_buf::with_big_struct::{closure#3}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
pinned_init::init_from_closure::<[core::mem::maybe_uninit::MaybeUninit<alloc_fail::ring_buf::EvenU64>; 4usize], core::convert::Infallible, <alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>>::new::{closure#0}::{closure#1}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
pinned_init::init_from_closure::<alloc_fail::ring_buf::BigStruct, core::alloc::AllocError, <alloc::sync::Arc<alloc_fail::ring_buf::BigStruct> as pinned_init::InPlaceInit<alloc_fail::ring_buf::BigStruct>>::init<pinned_init::__internal::InitClosure<alloc_fail::ring_buf::big_struct::{closure#1}, alloc_fail::ring_buf::BigStruct, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
pinned_init::init_from_closure::<alloc_fail::ring_buf::BigStruct, core::convert::Infallible, alloc_fail::ring_buf::big_struct::{closure#3}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
pinned_init::init_from_closure::<alloc_fail::ring_buf::EvenU64, (), <alloc_fail::ring_buf::EvenU64>::new::{closure#1}> Line | Count | Source | 1073 | 9 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 9 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 9 | ) -> impl Init<T, E> { | 1076 | 9 | __internal::InitClosure(f, PhantomData) | 1077 | 9 | } |
pinned_init::init_from_closure::<u8, core::convert::Infallible, <alloc_fail::ring_buf::RingBuffer<u8, 64usize>>::pop_no_stack::{closure#0}> Line | Count | Source | 1073 | 63 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 63 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 63 | ) -> impl Init<T, E> { | 1076 | 63 | __internal::InitClosure(f, PhantomData) | 1077 | 63 | } |
pinned_init::init_from_closure::<[u8; 1048576usize], core::convert::Infallible, pinned_init::zeroed<[u8; 1048576usize], core::convert::Infallible>::{closure#0}> Line | Count | Source | 1073 | 65 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 65 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 65 | ) -> impl Init<T, E> { | 1076 | 65 | __internal::InitClosure(f, PhantomData) | 1077 | 65 | } |
pinned_init::init_from_closure::<[core::mem::maybe_uninit::MaybeUninit<alloc_fail::ring_buf::BigStruct>; 64usize], core::convert::Infallible, <alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>::new::{closure#0}::{closure#1}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
pinned_init::init_from_closure::<[u8; 1099511627776usize], core::alloc::AllocError, <alloc::sync::Arc<[u8; 1099511627776usize]> as pinned_init::InPlaceInit<[u8; 1099511627776usize]>>::init<pinned_init::__internal::InitClosure<pinned_init::zeroed<[u8; 1099511627776usize], core::convert::Infallible>::{closure#0}, [u8; 1099511627776usize], core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
pinned_init::init_from_closure::<core::mem::maybe_uninit::MaybeUninit<u8>, core::convert::Infallible, pinned_init::uninit<u8, core::convert::Infallible>::{closure#0}> Line | Count | Source | 1073 | 63 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 63 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 63 | ) -> impl Init<T, E> { | 1076 | 63 | __internal::InitClosure(f, PhantomData) | 1077 | 63 | } |
pinned_init::init_from_closure::<core::mem::maybe_uninit::MaybeUninit<u8>, core::convert::Infallible, pinned_init::zeroed<core::mem::maybe_uninit::MaybeUninit<u8>, core::convert::Infallible>::{closure#0}> Line | Count | Source | 1073 | 2 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 2 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 2 | ) -> impl Init<T, E> { | 1076 | 2 | __internal::InitClosure(f, PhantomData) | 1077 | 2 | } |
pinned_init::init_from_closure::<[u8; 1099511627776usize], core::alloc::AllocError, <alloc::boxed::Box<[u8; 1099511627776usize]> as pinned_init::InPlaceInit<[u8; 1099511627776usize]>>::init<pinned_init::__internal::InitClosure<pinned_init::zeroed<[u8; 1099511627776usize], core::convert::Infallible>::{closure#0}, [u8; 1099511627776usize], core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
pinned_init::init_from_closure::<alloc_fail::ring_buf::BigStruct, core::convert::Infallible, alloc_fail::ring_buf::with_big_struct::{closure#1}> Line | Count | Source | 1073 | 63 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 63 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 63 | ) -> impl Init<T, E> { | 1076 | 63 | __internal::InitClosure(f, PhantomData) | 1077 | 63 | } |
pinned_init::init_from_closure::<[core::mem::maybe_uninit::MaybeUninit<u8>; 64usize], core::convert::Infallible, <alloc_fail::ring_buf::RingBuffer<u8, 64usize>>::new::{closure#0}::{closure#1}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
pinned_init::init_from_closure::<alloc_fail::ring_buf::BigStruct, core::alloc::AllocError, <alloc::boxed::Box<alloc_fail::ring_buf::BigStruct> as pinned_init::InPlaceInit<alloc_fail::ring_buf::BigStruct>>::init<pinned_init::__internal::InitClosure<alloc_fail::ring_buf::big_struct::{closure#3}, alloc_fail::ring_buf::BigStruct, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
Unexecuted instantiation: pinned_init::init_from_closure::<_, _, _> pinned_init::init_from_closure::<pinned_init::__internal::stack_init_reuse::Foo, core::convert::Infallible, pinned_init::__internal::stack_init_reuse::{closure#3}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
pinned_init::init_from_closure::<pinned_init::__internal::stack_init_reuse::Foo, core::convert::Infallible, pinned_init::__internal::stack_init_reuse::{closure#1}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
pinned_init::init_from_closure::<ring_buf::BigStruct, core::alloc::AllocError, <alloc::sync::Arc<ring_buf::BigStruct> as pinned_init::InPlaceInit<ring_buf::BigStruct>>::init<pinned_init::__internal::InitClosure<ring_buf::big_struct::{closure#1}, ring_buf::BigStruct, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
pinned_init::init_from_closure::<ring_buf::EvenU64, (), <ring_buf::EvenU64>::new::{closure#1}> Line | Count | Source | 1073 | 9 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 9 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 9 | ) -> impl Init<T, E> { | 1076 | 9 | __internal::InitClosure(f, PhantomData) | 1077 | 9 | } |
pinned_init::init_from_closure::<ring_buf::BigStruct, core::convert::Infallible, ring_buf::with_big_struct::{closure#3}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
pinned_init::init_from_closure::<u8, core::convert::Infallible, <ring_buf::RingBuffer<u8, 64usize>>::pop_no_stack::{closure#0}> Line | Count | Source | 1073 | 63 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 63 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 63 | ) -> impl Init<T, E> { | 1076 | 63 | __internal::InitClosure(f, PhantomData) | 1077 | 63 | } |
pinned_init::init_from_closure::<ring_buf::BigStruct, core::convert::Infallible, ring_buf::big_struct::{closure#1}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
pinned_init::init_from_closure::<core::mem::maybe_uninit::MaybeUninit<u8>, core::convert::Infallible, pinned_init::zeroed<core::mem::maybe_uninit::MaybeUninit<u8>, core::convert::Infallible>::{closure#0}> Line | Count | Source | 1073 | 2 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 2 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 2 | ) -> impl Init<T, E> { | 1076 | 2 | __internal::InitClosure(f, PhantomData) | 1077 | 2 | } |
pinned_init::init_from_closure::<core::mem::maybe_uninit::MaybeUninit<u8>, core::convert::Infallible, pinned_init::uninit<u8, core::convert::Infallible>::{closure#0}> Line | Count | Source | 1073 | 63 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 63 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 63 | ) -> impl Init<T, E> { | 1076 | 63 | __internal::InitClosure(f, PhantomData) | 1077 | 63 | } |
pinned_init::init_from_closure::<ring_buf::BigStruct, core::convert::Infallible, ring_buf::with_big_struct::{closure#1}> Line | Count | Source | 1073 | 63 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 63 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 63 | ) -> impl Init<T, E> { | 1076 | 63 | __internal::InitClosure(f, PhantomData) | 1077 | 63 | } |
pinned_init::init_from_closure::<ring_buf::BigStruct, core::convert::Infallible, <ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>::pop_no_stack::{closure#0}> Line | Count | Source | 1073 | 63 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 63 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 63 | ) -> impl Init<T, E> { | 1076 | 63 | __internal::InitClosure(f, PhantomData) | 1077 | 63 | } |
pinned_init::init_from_closure::<[core::mem::maybe_uninit::MaybeUninit<ring_buf::BigStruct>; 64usize], core::convert::Infallible, <ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>::new::{closure#0}::{closure#1}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
pinned_init::init_from_closure::<ring_buf::EvenU64, core::alloc::AllocError, <ring_buf::EvenU64>::new2::{closure#1}> Line | Count | Source | 1073 | 4 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 4 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 4 | ) -> impl Init<T, E> { | 1076 | 4 | __internal::InitClosure(f, PhantomData) | 1077 | 4 | } |
pinned_init::init_from_closure::<[core::mem::maybe_uninit::MaybeUninit<u8>; 64usize], core::convert::Infallible, <ring_buf::RingBuffer<u8, 64usize>>::new::{closure#0}::{closure#1}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
pinned_init::init_from_closure::<ring_buf::BigStruct, core::convert::Infallible, ring_buf::big_struct::{closure#3}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
pinned_init::init_from_closure::<[core::mem::maybe_uninit::MaybeUninit<ring_buf::EvenU64>; 4usize], core::convert::Infallible, <ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>>::new::{closure#0}::{closure#1}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
pinned_init::init_from_closure::<ring_buf::BigStruct, core::alloc::AllocError, <alloc::boxed::Box<ring_buf::BigStruct> as pinned_init::InPlaceInit<ring_buf::BigStruct>>::init<pinned_init::__internal::InitClosure<ring_buf::big_struct::{closure#3}, ring_buf::BigStruct, core::convert::Infallible>>::{closure#0}> Line | Count | Source | 1073 | 1 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 1 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 1 | ) -> impl Init<T, E> { | 1076 | 1 | __internal::InitClosure(f, PhantomData) | 1077 | 1 | } |
pinned_init::init_from_closure::<[u8; 1048576usize], core::convert::Infallible, pinned_init::zeroed<[u8; 1048576usize], core::convert::Infallible>::{closure#0}> Line | Count | Source | 1073 | 65 | pub const unsafe fn init_from_closure<T: ?Sized, E>( | 1074 | 65 | f: impl FnOnce(*mut T) -> Result<(), E>, | 1075 | 65 | ) -> impl Init<T, E> { | 1076 | 65 | __internal::InitClosure(f, PhantomData) | 1077 | 65 | } |
|
1078 | | |
1079 | | /// An initializer that leaves the memory uninitialized. |
1080 | | /// |
1081 | | /// The initializer is a no-op. The `slot` memory is not changed. |
1082 | | #[inline] |
1083 | 126 | pub fn uninit<T, E>() -> impl Init<MaybeUninit<T>, E> { |
1084 | 126 | // SAFETY: The memory is allowed to be uninitialized. |
1085 | 126 | unsafe { init_from_closure(|_| Ok(())) } pinned_init::uninit::<u8, core::convert::Infallible>::{closure#0} Line | Count | Source | 1085 | 63 | unsafe { init_from_closure(|_| Ok(())) } |
Unexecuted instantiation: pinned_init::uninit::<_, _>::{closure#0} Unexecuted instantiation: pinned_init::uninit::<_, _>::{closure#0} pinned_init::uninit::<u8, core::convert::Infallible>::{closure#0} Line | Count | Source | 1085 | 63 | unsafe { init_from_closure(|_| Ok(())) } |
|
1086 | 126 | } pinned_init::uninit::<u8, core::convert::Infallible> Line | Count | Source | 1083 | 63 | pub fn uninit<T, E>() -> impl Init<MaybeUninit<T>, E> { | 1084 | 63 | // SAFETY: The memory is allowed to be uninitialized. | 1085 | 63 | unsafe { init_from_closure(|_| Ok(())) } | 1086 | 63 | } |
Unexecuted instantiation: pinned_init::uninit::<_, _> Unexecuted instantiation: pinned_init::uninit::<_, _> pinned_init::uninit::<u8, core::convert::Infallible> Line | Count | Source | 1083 | 63 | pub fn uninit<T, E>() -> impl Init<MaybeUninit<T>, E> { | 1084 | 63 | // SAFETY: The memory is allowed to be uninitialized. | 1085 | 63 | unsafe { init_from_closure(|_| Ok(())) } | 1086 | 63 | } |
|
1087 | | |
1088 | | /// Initializes an array by initializing each element via the provided initializer. |
1089 | | /// |
1090 | | /// # Examples |
1091 | | /// |
1092 | | /// ```rust |
1093 | | /// # use pinned_init::*; |
1094 | | /// let array: Box<[usize; 1000]>= Box::init(init_array_from_fn(|i| i)).unwrap(); |
1095 | | /// println!("{array:?}"); |
1096 | | /// ``` |
1097 | 0 | pub fn init_array_from_fn<I, const N: usize, T, E>( |
1098 | 0 | mut make_init: impl FnMut(usize) -> I, |
1099 | 0 | ) -> impl Init<[T; N], E> |
1100 | 0 | where |
1101 | 0 | I: Init<T, E>, |
1102 | 0 | { |
1103 | 0 | let init = move |slot: *mut [T; N]| { |
1104 | 0 | let slot = slot.cast::<T>(); |
1105 | 0 | for i in 0..N { |
1106 | 0 | let init = make_init(i); |
1107 | 0 | // SAFETY: since 0 <= `i` < N, it is still in bounds of `[T; N]`. |
1108 | 0 | let ptr = unsafe { slot.add(i) }; |
1109 | 0 | // SAFETY: The pointer is derived from `slot` and thus satisfies the `__init` |
1110 | 0 | // requirements. |
1111 | 0 | match unsafe { init.__init(ptr) } { |
1112 | 0 | Ok(()) => {} |
1113 | 0 | Err(e) => { |
1114 | 0 | // We now free every element that has been initialized before: |
1115 | 0 | // SAFETY: The loop initialized exactly the values from 0..i and since we |
1116 | 0 | // return `Err` below, the caller will consider the memory at `slot` as |
1117 | 0 | // uninitialized. |
1118 | 0 | unsafe { ptr::drop_in_place(ptr::slice_from_raw_parts_mut(slot, i)) }; |
1119 | 0 | return Err(e); |
1120 | | } |
1121 | | } |
1122 | | } |
1123 | 0 | Ok(()) |
1124 | 0 | }; Unexecuted instantiation: pinned_init::init_array_from_fn::<_, _, _, _, _>::{closure#0} Unexecuted instantiation: pinned_init::init_array_from_fn::<_, _, _, _, _>::{closure#0} |
1125 | | // SAFETY: The initializer above initializes every element of the array. On failure it drops |
1126 | | // any initialized elements and returns `Err`. |
1127 | 0 | unsafe { init_from_closure(init) } |
1128 | 0 | } Unexecuted instantiation: pinned_init::init_array_from_fn::<_, _, _, _, _> Unexecuted instantiation: pinned_init::init_array_from_fn::<_, _, _, _, _> |
1129 | | |
1130 | | /// Initializes an array by initializing each element via the provided initializer. |
1131 | | /// |
1132 | | /// # Examples |
1133 | | /// |
1134 | | /// ```rust |
1135 | | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)] |
1136 | | /// # #![feature(allocator_api, no_coverage)] |
1137 | | /// # use pinned_init::*; |
1138 | | /// # use core::pin::Pin; |
1139 | | /// # #[path = "../examples/mutex.rs"] mod mutex; use mutex::*; |
1140 | | /// # extern crate alloc; |
1141 | | /// # use alloc::sync::Arc; |
1142 | | /// # use core::convert::Infallible; |
1143 | | /// let array: Pin<Arc<[CMutex<usize>; 1000]>>= |
1144 | | /// Arc::pin_init(pin_init_array_from_fn(|i| CMutex::new(i))).unwrap(); |
1145 | | /// println!("{array:?}"); |
1146 | | /// ``` |
1147 | 0 | pub fn pin_init_array_from_fn<I, const N: usize, T, E>( |
1148 | 0 | mut make_init: impl FnMut(usize) -> I, |
1149 | 0 | ) -> impl PinInit<[T; N], E> |
1150 | 0 | where |
1151 | 0 | I: PinInit<T, E>, |
1152 | 0 | { |
1153 | 0 | let init = move |slot: *mut [T; N]| { |
1154 | 0 | let slot = slot.cast::<T>(); |
1155 | 0 | for i in 0..N { |
1156 | 0 | let init = make_init(i); |
1157 | 0 | // SAFETY: since 0 <= `i` < N, it is still in bounds of `[T; N]`. |
1158 | 0 | let ptr = unsafe { slot.add(i) }; |
1159 | 0 | // SAFETY: The pointer is derived from `slot` and thus satisfies the `__pinned_init` |
1160 | 0 | // requirements. |
1161 | 0 | match unsafe { init.__pinned_init(ptr) } { |
1162 | 0 | Ok(()) => {} |
1163 | 0 | Err(e) => { |
1164 | 0 | // We now have to free every element that has been initialized before, since we |
1165 | 0 | // have to abide by the drop guarantee. |
1166 | 0 | // SAFETY: The loop initialized exactly the values from 0..i and since we |
1167 | 0 | // return `Err` below, the caller will consider the memory at `slot` as |
1168 | 0 | // uninitialized. |
1169 | 0 | unsafe { ptr::drop_in_place(ptr::slice_from_raw_parts_mut(slot, i)) }; |
1170 | 0 | return Err(e); |
1171 | | } |
1172 | | } |
1173 | | } |
1174 | 0 | Ok(()) |
1175 | 0 | }; Unexecuted instantiation: pinned_init::pin_init_array_from_fn::<_, _, _, _, _>::{closure#0} Unexecuted instantiation: pinned_init::pin_init_array_from_fn::<_, _, _, _, _>::{closure#0} |
1176 | | // SAFETY: The initializer above initializes every element of the array. On failure it drops |
1177 | | // any initialized elements and returns `Err`. |
1178 | 0 | unsafe { pin_init_from_closure(init) } |
1179 | 0 | } Unexecuted instantiation: pinned_init::pin_init_array_from_fn::<_, _, _, _, _> Unexecuted instantiation: pinned_init::pin_init_array_from_fn::<_, _, _, _, _> |
1180 | | |
1181 | | // SAFETY: Every type can be initialized by-value. |
1182 | | unsafe impl<T, E> Init<T, E> for T { |
1183 | 140 | unsafe fn __init(self, slot: *mut T) -> Result<(), E> { |
1184 | 140 | unsafe { slot.write(self) }; |
1185 | 140 | Ok(()) |
1186 | 140 | } <usize as pinned_init::Init<usize>>::__init Line | Count | Source | 1183 | 1 | unsafe fn __init(self, slot: *mut T) -> Result<(), E> { | 1184 | 1 | unsafe { slot.write(self) }; | 1185 | 1 | Ok(()) | 1186 | 1 | } |
<u8 as pinned_init::Init<u8>>::__init Line | Count | Source | 1183 | 68 | unsafe fn __init(self, slot: *mut T) -> Result<(), E> { | 1184 | 68 | unsafe { slot.write(self) }; | 1185 | 68 | Ok(()) | 1186 | 68 | } |
Unexecuted instantiation: <_ as pinned_init::Init<_, _>>::__init Unexecuted instantiation: <_ as pinned_init::Init<_, _>>::__init <u8 as pinned_init::Init<u8>>::__init Line | Count | Source | 1183 | 68 | unsafe fn __init(self, slot: *mut T) -> Result<(), E> { | 1184 | 68 | unsafe { slot.write(self) }; | 1185 | 68 | Ok(()) | 1186 | 68 | } |
<usize as pinned_init::Init<usize>>::__init Line | Count | Source | 1183 | 1 | unsafe fn __init(self, slot: *mut T) -> Result<(), E> { | 1184 | 1 | unsafe { slot.write(self) }; | 1185 | 1 | Ok(()) | 1186 | 1 | } |
<usize as pinned_init::Init<usize>>::__init Line | Count | Source | 1183 | 1 | unsafe fn __init(self, slot: *mut T) -> Result<(), E> { | 1184 | 1 | unsafe { slot.write(self) }; | 1185 | 1 | Ok(()) | 1186 | 1 | } |
<usize as pinned_init::Init<usize>>::__init Line | Count | Source | 1183 | 1 | unsafe fn __init(self, slot: *mut T) -> Result<(), E> { | 1184 | 1 | unsafe { slot.write(self) }; | 1185 | 1 | Ok(()) | 1186 | 1 | } |
|
1187 | | } |
1188 | | // SAFETY: Every type can be initialized by-value. `__pinned_init` calls `__init`. |
1189 | | unsafe impl<T, E> PinInit<T, E> for T { |
1190 | 4 | unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> { |
1191 | 4 | unsafe { self.__init(slot) } |
1192 | 4 | } <usize as pinned_init::PinInit<usize>>::__pinned_init Line | Count | Source | 1190 | 1 | unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> { | 1191 | 1 | unsafe { self.__init(slot) } | 1192 | 1 | } |
Unexecuted instantiation: <_ as pinned_init::PinInit<_, _>>::__pinned_init Unexecuted instantiation: <_ as pinned_init::PinInit<_, _>>::__pinned_init <usize as pinned_init::PinInit<usize>>::__pinned_init Line | Count | Source | 1190 | 1 | unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> { | 1191 | 1 | unsafe { self.__init(slot) } | 1192 | 1 | } |
<usize as pinned_init::PinInit<usize>>::__pinned_init Line | Count | Source | 1190 | 1 | unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> { | 1191 | 1 | unsafe { self.__init(slot) } | 1192 | 1 | } |
<usize as pinned_init::PinInit<usize>>::__pinned_init Line | Count | Source | 1190 | 1 | unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> { | 1191 | 1 | unsafe { self.__init(slot) } | 1192 | 1 | } |
|
1193 | | } |
1194 | | |
1195 | | /// Smart pointer that can initialize memory in-place. |
1196 | | pub trait InPlaceInit<T>: Sized { |
1197 | | /// Use the given pin-initializer to pin-initialize a `T` inside of a new smart pointer of this |
1198 | | /// type. |
1199 | | /// |
1200 | | /// If `T: !Unpin` it will not be able to move afterwards. |
1201 | | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> |
1202 | | where |
1203 | | E: From<AllocError>; |
1204 | | |
1205 | | /// Use the given pin-initializer to pin-initialize a `T` inside of a new smart pointer of this |
1206 | | /// type. |
1207 | | /// |
1208 | | /// If `T: !Unpin` it will not be able to move afterwards. |
1209 | 20 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { |
1210 | 20 | // SAFETY: We delegate to `init` and only change the error type. |
1211 | 20 | let init = unsafe { |
1212 | 20 | pin_init_from_closure(|slot| { |
1213 | 18 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail |
1214 | 20 | }) <alloc::sync::Arc<alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>>>::pin_init::<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>>::new<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>::new::{closure#1}, alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>, core::convert::Infallible>>::{closure#1}, alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | 1 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) |
<alloc::boxed::Box<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>>>::pin_init::<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>>::new::{closure#1}, alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | 1 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) |
<alloc::sync::Arc<alloc_fail::ring_buf::mutex::CMutex<usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::CMutex<usize>>>::pin_init::<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::mutex::CMutex<usize>>::new<usize>::{closure#1}, alloc_fail::ring_buf::mutex::CMutex<usize>, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | 1 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) |
<alloc::boxed::Box<alloc_fail::ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::mutex::linked_list::ListHead>::new::{closure#1}, alloc_fail::ring_buf::mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | 1 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) |
Unexecuted instantiation: <alloc::boxed::Box<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>>::pin_init::<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>::new::{closure#1}, alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>, core::convert::Infallible>>::{closure#0} Unexecuted instantiation: <alloc::sync::Arc<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>>::pin_init::<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>::new::{closure#1}, alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>, core::convert::Infallible>>::{closure#0} <alloc::boxed::Box<alloc_fail::ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::mutex::linked_list::ListHead>::insert_next::{closure#1}, alloc_fail::ring_buf::mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | 1 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) |
Unexecuted instantiation: <_ as pinned_init::InPlaceInit<_>>::pin_init::<_>::{closure#0} Unexecuted instantiation: <_ as pinned_init::InPlaceInit<_>>::pin_init::<_>::{closure#0} <alloc::boxed::Box<ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<ring_buf::mutex::linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<ring_buf::mutex::linked_list::ListHead>::insert_next::{closure#1}, ring_buf::mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | 1 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) |
<alloc::sync::Arc<ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>> as pinned_init::InPlaceInit<ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>>>::pin_init::<pinned_init::__internal::InitClosure<<ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>>::new<pinned_init::__internal::InitClosure<<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>::new::{closure#1}, ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>, core::convert::Infallible>>::{closure#1}, ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | 1 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) |
<alloc::boxed::Box<ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>> as pinned_init::InPlaceInit<ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>>>::pin_init::<pinned_init::__internal::InitClosure<<ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>>::new::{closure#1}, ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | 1 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) |
<alloc::boxed::Box<ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<ring_buf::mutex::linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<ring_buf::mutex::linked_list::ListHead>::new::{closure#1}, ring_buf::mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | 1 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) |
<alloc::sync::Arc<ring_buf::mutex::CMutex<usize>> as pinned_init::InPlaceInit<ring_buf::mutex::CMutex<usize>>>::pin_init::<pinned_init::__internal::InitClosure<<ring_buf::mutex::CMutex<usize>>::new<usize>::{closure#1}, ring_buf::mutex::CMutex<usize>, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | 1 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) |
<alloc::boxed::Box<linked_list::ListHead> as pinned_init::InPlaceInit<linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<linked_list::ListHead>::new::{closure#1}, linked_list::ListHead, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | 1 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) |
<alloc::boxed::Box<linked_list::ListHead> as pinned_init::InPlaceInit<linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<linked_list::ListHead>::insert_next::{closure#1}, linked_list::ListHead, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | 1 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) |
<alloc::boxed::Box<mutex::linked_list::ListHead> as pinned_init::InPlaceInit<mutex::linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<mutex::linked_list::ListHead>::insert_next::{closure#1}, mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | 1 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) |
<alloc::sync::Arc<mutex::CMutex<usize>> as pinned_init::InPlaceInit<mutex::CMutex<usize>>>::pin_init::<pinned_init::__internal::InitClosure<<mutex::CMutex<usize>>::new<usize>::{closure#1}, mutex::CMutex<usize>, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | 1 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) |
<alloc::boxed::Box<mutex::linked_list::ListHead> as pinned_init::InPlaceInit<mutex::linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<mutex::linked_list::ListHead>::new::{closure#1}, mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | 1 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) |
<alloc::sync::Arc<static_init::mutex::CMutex<usize>> as pinned_init::InPlaceInit<static_init::mutex::CMutex<usize>>>::pin_init::<pinned_init::__internal::InitClosure<<static_init::mutex::CMutex<usize>>::new<usize>::{closure#1}, static_init::mutex::CMutex<usize>, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | 1 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) |
<alloc::boxed::Box<static_init::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<static_init::mutex::linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<static_init::mutex::linked_list::ListHead>::insert_next::{closure#1}, static_init::mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | 1 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) |
<alloc::boxed::Box<static_init::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<static_init::mutex::linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<static_init::mutex::linked_list::ListHead>::new::{closure#1}, static_init::mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | 1 | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) |
|
1215 | 20 | }; |
1216 | 20 | Self::try_pin_init(init) |
1217 | 20 | } <alloc::sync::Arc<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>>::pin_init::<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>::new::{closure#1}, alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
<alloc::sync::Arc<alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>>>::pin_init::<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>>::new<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>::new::{closure#1}, alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>, core::convert::Infallible>>::{closure#1}, alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
<alloc::sync::Arc<alloc_fail::ring_buf::mutex::CMutex<usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::CMutex<usize>>>::pin_init::<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::mutex::CMutex<usize>>::new<usize>::{closure#1}, alloc_fail::ring_buf::mutex::CMutex<usize>, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
<alloc::boxed::Box<alloc_fail::ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::mutex::linked_list::ListHead>::new::{closure#1}, alloc_fail::ring_buf::mutex::linked_list::ListHead, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
<alloc::boxed::Box<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>>::pin_init::<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>::new::{closure#1}, alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
<alloc::boxed::Box<alloc_fail::ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::mutex::linked_list::ListHead>::insert_next::{closure#1}, alloc_fail::ring_buf::mutex::linked_list::ListHead, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
<alloc::boxed::Box<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>>>::pin_init::<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>>::new::{closure#1}, alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
Unexecuted instantiation: <_ as pinned_init::InPlaceInit<_>>::pin_init::<_> Unexecuted instantiation: <_ as pinned_init::InPlaceInit<_>>::pin_init::<_> <alloc::sync::Arc<ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>> as pinned_init::InPlaceInit<ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>>>::pin_init::<pinned_init::__internal::InitClosure<<ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>>::new<pinned_init::__internal::InitClosure<<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>::new::{closure#1}, ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>, core::convert::Infallible>>::{closure#1}, ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
<alloc::sync::Arc<ring_buf::mutex::CMutex<usize>> as pinned_init::InPlaceInit<ring_buf::mutex::CMutex<usize>>>::pin_init::<pinned_init::__internal::InitClosure<<ring_buf::mutex::CMutex<usize>>::new<usize>::{closure#1}, ring_buf::mutex::CMutex<usize>, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
<alloc::boxed::Box<ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<ring_buf::mutex::linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<ring_buf::mutex::linked_list::ListHead>::insert_next::{closure#1}, ring_buf::mutex::linked_list::ListHead, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
<alloc::boxed::Box<ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>> as pinned_init::InPlaceInit<ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>>>::pin_init::<pinned_init::__internal::InitClosure<<ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>>::new::{closure#1}, ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
<alloc::boxed::Box<ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<ring_buf::mutex::linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<ring_buf::mutex::linked_list::ListHead>::new::{closure#1}, ring_buf::mutex::linked_list::ListHead, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
<alloc::boxed::Box<linked_list::ListHead> as pinned_init::InPlaceInit<linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<linked_list::ListHead>::new::{closure#1}, linked_list::ListHead, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
<alloc::boxed::Box<linked_list::ListHead> as pinned_init::InPlaceInit<linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<linked_list::ListHead>::insert_next::{closure#1}, linked_list::ListHead, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
<alloc::boxed::Box<mutex::linked_list::ListHead> as pinned_init::InPlaceInit<mutex::linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<mutex::linked_list::ListHead>::insert_next::{closure#1}, mutex::linked_list::ListHead, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
<alloc::boxed::Box<mutex::linked_list::ListHead> as pinned_init::InPlaceInit<mutex::linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<mutex::linked_list::ListHead>::new::{closure#1}, mutex::linked_list::ListHead, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
<alloc::sync::Arc<mutex::CMutex<usize>> as pinned_init::InPlaceInit<mutex::CMutex<usize>>>::pin_init::<pinned_init::__internal::InitClosure<<mutex::CMutex<usize>>::new<usize>::{closure#1}, mutex::CMutex<usize>, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
<alloc::sync::Arc<static_init::mutex::CMutex<usize>> as pinned_init::InPlaceInit<static_init::mutex::CMutex<usize>>>::pin_init::<pinned_init::__internal::InitClosure<<static_init::mutex::CMutex<usize>>::new<usize>::{closure#1}, static_init::mutex::CMutex<usize>, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
<alloc::boxed::Box<static_init::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<static_init::mutex::linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<static_init::mutex::linked_list::ListHead>::new::{closure#1}, static_init::mutex::linked_list::ListHead, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
<alloc::boxed::Box<static_init::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<static_init::mutex::linked_list::ListHead>>::pin_init::<pinned_init::__internal::InitClosure<<static_init::mutex::linked_list::ListHead>::insert_next::{closure#1}, static_init::mutex::linked_list::ListHead, core::convert::Infallible>> Line | Count | Source | 1209 | 1 | fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> { | 1210 | 1 | // SAFETY: We delegate to `init` and only change the error type. | 1211 | 1 | let init = unsafe { | 1212 | 1 | pin_init_from_closure(|slot| { | 1213 | | Ok(init.__pinned_init(slot).unwrap()) // cannot fail | 1214 | 1 | }) | 1215 | 1 | }; | 1216 | 1 | Self::try_pin_init(init) | 1217 | 1 | } |
|
1218 | | |
1219 | | /// Use the given initializer to in-place initialize a `T`. |
1220 | | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E> |
1221 | | where |
1222 | | E: From<AllocError>; |
1223 | | |
1224 | | /// Use the given initializer to in-place initialize a `T`. |
1225 | 6 | fn init(init: impl Init<T>) -> Result<Self, AllocError> { |
1226 | 6 | let init = unsafe { |
1227 | 6 | init_from_closure(|slot| Ok(init.__init(slot).unwrap())4 ) //cannot fail Unexecuted instantiation: <alloc::boxed::Box<[u8; 1099511627776usize]> as pinned_init::InPlaceInit<[u8; 1099511627776usize]>>::init::<pinned_init::__internal::InitClosure<pinned_init::zeroed<[u8; 1099511627776usize], core::convert::Infallible>::{closure#0}, [u8; 1099511627776usize], core::convert::Infallible>>::{closure#0} <alloc::sync::Arc<alloc_fail::ring_buf::BigStruct> as pinned_init::InPlaceInit<alloc_fail::ring_buf::BigStruct>>::init::<pinned_init::__internal::InitClosure<alloc_fail::ring_buf::big_struct::{closure#1}, alloc_fail::ring_buf::BigStruct, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1227 | 1 | init_from_closure(|slot| Ok(init.__init(slot).unwrap())) //cannot fail |
<alloc::boxed::Box<alloc_fail::ring_buf::BigStruct> as pinned_init::InPlaceInit<alloc_fail::ring_buf::BigStruct>>::init::<pinned_init::__internal::InitClosure<alloc_fail::ring_buf::big_struct::{closure#3}, alloc_fail::ring_buf::BigStruct, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1227 | 1 | init_from_closure(|slot| Ok(init.__init(slot).unwrap())) //cannot fail |
Unexecuted instantiation: <alloc::sync::Arc<[u8; 1099511627776usize]> as pinned_init::InPlaceInit<[u8; 1099511627776usize]>>::init::<pinned_init::__internal::InitClosure<pinned_init::zeroed<[u8; 1099511627776usize], core::convert::Infallible>::{closure#0}, [u8; 1099511627776usize], core::convert::Infallible>>::{closure#0} Unexecuted instantiation: <_ as pinned_init::InPlaceInit<_>>::init::<_>::{closure#0} Unexecuted instantiation: <_ as pinned_init::InPlaceInit<_>>::init::<_>::{closure#0} <alloc::sync::Arc<ring_buf::BigStruct> as pinned_init::InPlaceInit<ring_buf::BigStruct>>::init::<pinned_init::__internal::InitClosure<ring_buf::big_struct::{closure#1}, ring_buf::BigStruct, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1227 | 1 | init_from_closure(|slot| Ok(init.__init(slot).unwrap())) //cannot fail |
<alloc::boxed::Box<ring_buf::BigStruct> as pinned_init::InPlaceInit<ring_buf::BigStruct>>::init::<pinned_init::__internal::InitClosure<ring_buf::big_struct::{closure#3}, ring_buf::BigStruct, core::convert::Infallible>>::{closure#0} Line | Count | Source | 1227 | 1 | init_from_closure(|slot| Ok(init.__init(slot).unwrap())) //cannot fail |
|
1228 | 6 | }; |
1229 | 6 | Self::try_init(init) |
1230 | 6 | } <alloc::sync::Arc<alloc_fail::ring_buf::BigStruct> as pinned_init::InPlaceInit<alloc_fail::ring_buf::BigStruct>>::init::<pinned_init::__internal::InitClosure<alloc_fail::ring_buf::big_struct::{closure#1}, alloc_fail::ring_buf::BigStruct, core::convert::Infallible>> Line | Count | Source | 1225 | 1 | fn init(init: impl Init<T>) -> Result<Self, AllocError> { | 1226 | 1 | let init = unsafe { | 1227 | 1 | init_from_closure(|slot| Ok(init.__init(slot).unwrap())) //cannot fail | 1228 | 1 | }; | 1229 | 1 | Self::try_init(init) | 1230 | 1 | } |
<alloc::sync::Arc<[u8; 1099511627776usize]> as pinned_init::InPlaceInit<[u8; 1099511627776usize]>>::init::<pinned_init::__internal::InitClosure<pinned_init::zeroed<[u8; 1099511627776usize], core::convert::Infallible>::{closure#0}, [u8; 1099511627776usize], core::convert::Infallible>> Line | Count | Source | 1225 | 1 | fn init(init: impl Init<T>) -> Result<Self, AllocError> { | 1226 | 1 | let init = unsafe { | 1227 | 1 | init_from_closure(|slot| Ok(init.__init(slot).unwrap())) //cannot fail | 1228 | 1 | }; | 1229 | 1 | Self::try_init(init) | 1230 | 1 | } |
<alloc::boxed::Box<alloc_fail::ring_buf::BigStruct> as pinned_init::InPlaceInit<alloc_fail::ring_buf::BigStruct>>::init::<pinned_init::__internal::InitClosure<alloc_fail::ring_buf::big_struct::{closure#3}, alloc_fail::ring_buf::BigStruct, core::convert::Infallible>> Line | Count | Source | 1225 | 1 | fn init(init: impl Init<T>) -> Result<Self, AllocError> { | 1226 | 1 | let init = unsafe { | 1227 | 1 | init_from_closure(|slot| Ok(init.__init(slot).unwrap())) //cannot fail | 1228 | 1 | }; | 1229 | 1 | Self::try_init(init) | 1230 | 1 | } |
<alloc::boxed::Box<[u8; 1099511627776usize]> as pinned_init::InPlaceInit<[u8; 1099511627776usize]>>::init::<pinned_init::__internal::InitClosure<pinned_init::zeroed<[u8; 1099511627776usize], core::convert::Infallible>::{closure#0}, [u8; 1099511627776usize], core::convert::Infallible>> Line | Count | Source | 1225 | 1 | fn init(init: impl Init<T>) -> Result<Self, AllocError> { | 1226 | 1 | let init = unsafe { | 1227 | 1 | init_from_closure(|slot| Ok(init.__init(slot).unwrap())) //cannot fail | 1228 | 1 | }; | 1229 | 1 | Self::try_init(init) | 1230 | 1 | } |
Unexecuted instantiation: <_ as pinned_init::InPlaceInit<_>>::init::<_> Unexecuted instantiation: <_ as pinned_init::InPlaceInit<_>>::init::<_> <alloc::sync::Arc<ring_buf::BigStruct> as pinned_init::InPlaceInit<ring_buf::BigStruct>>::init::<pinned_init::__internal::InitClosure<ring_buf::big_struct::{closure#1}, ring_buf::BigStruct, core::convert::Infallible>> Line | Count | Source | 1225 | 1 | fn init(init: impl Init<T>) -> Result<Self, AllocError> { | 1226 | 1 | let init = unsafe { | 1227 | 1 | init_from_closure(|slot| Ok(init.__init(slot).unwrap())) //cannot fail | 1228 | 1 | }; | 1229 | 1 | Self::try_init(init) | 1230 | 1 | } |
<alloc::boxed::Box<ring_buf::BigStruct> as pinned_init::InPlaceInit<ring_buf::BigStruct>>::init::<pinned_init::__internal::InitClosure<ring_buf::big_struct::{closure#3}, ring_buf::BigStruct, core::convert::Infallible>> Line | Count | Source | 1225 | 1 | fn init(init: impl Init<T>) -> Result<Self, AllocError> { | 1226 | 1 | let init = unsafe { | 1227 | 1 | init_from_closure(|slot| Ok(init.__init(slot).unwrap())) //cannot fail | 1228 | 1 | }; | 1229 | 1 | Self::try_init(init) | 1230 | 1 | } |
|
1231 | | } |
1232 | | |
1233 | | #[cfg(any(feature = "alloc"))] |
1234 | | impl<T> InPlaceInit<T> for Box<T> { |
1235 | | #[inline] |
1236 | 15 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> |
1237 | 15 | where |
1238 | 15 | E: From<AllocError>, |
1239 | 15 | { |
1240 | 15 | let mut this14 = Box::try_new_uninit()?1 ; |
1241 | 14 | let slot = this.as_mut_ptr(); |
1242 | 14 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, |
1243 | 14 | // slot is valid and will not be moved, because we pin it later. |
1244 | 14 | unsafe { init.__pinned_init(slot)?2 }; |
1245 | | // SAFETY: All fields have been initialized. |
1246 | 12 | Ok(unsafe { this.assume_init() }.into()) |
1247 | 15 | } <alloc::boxed::Box<alloc_fail::ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::linked_list::ListHead>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::boxed::Box<alloc_fail::ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::mutex::linked_list::ListHead>::insert_next::{closure#1}, alloc_fail::ring_buf::mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0}, alloc_fail::ring_buf::mutex::linked_list::ListHead, core::alloc::AllocError>> Line | Count | Source | 1236 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1237 | 1 | where | 1238 | 1 | E: From<AllocError>, | 1239 | 1 | { | 1240 | 1 | let mut this = Box::try_new_uninit()?0 ; | 1241 | 1 | let slot = this.as_mut_ptr(); | 1242 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1243 | 1 | // slot is valid and will not be moved, because we pin it later. | 1244 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1245 | | // SAFETY: All fields have been initialized. | 1246 | 1 | Ok(unsafe { this.assume_init() }.into()) | 1247 | 1 | } |
<alloc::boxed::Box<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::boxed::Box<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>>>::pin_init<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>>::new::{closure#1}, alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>, core::convert::Infallible>>::{closure#0}, alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::EvenU64, 4usize>, core::alloc::AllocError>> Line | Count | Source | 1236 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1237 | 1 | where | 1238 | 1 | E: From<AllocError>, | 1239 | 1 | { | 1240 | 1 | let mut this = Box::try_new_uninit()?0 ; | 1241 | 1 | let slot = this.as_mut_ptr(); | 1242 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1243 | 1 | // slot is valid and will not be moved, because we pin it later. | 1244 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1245 | | // SAFETY: All fields have been initialized. | 1246 | 1 | Ok(unsafe { this.assume_init() }.into()) | 1247 | 1 | } |
<alloc::boxed::Box<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::boxed::Box<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>>::pin_init<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>::new::{closure#1}, alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>, core::convert::Infallible>>::{closure#0}, alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>, core::alloc::AllocError>> Line | Count | Source | 1236 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1237 | 1 | where | 1238 | 1 | E: From<AllocError>, | 1239 | 1 | { | 1240 | 1 | let mut this0 = Box::try_new_uninit()?; | 1241 | 0 | let slot = this.as_mut_ptr(); | 1242 | 0 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1243 | 0 | // slot is valid and will not be moved, because we pin it later. | 1244 | 0 | unsafe { init.__pinned_init(slot)? }; | 1245 | | // SAFETY: All fields have been initialized. | 1246 | 0 | Ok(unsafe { this.assume_init() }.into()) | 1247 | 1 | } |
<alloc::boxed::Box<alloc_fail::ring_buf::EvenU64> as pinned_init::InPlaceInit<alloc_fail::ring_buf::EvenU64>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::EvenU64>::new2::{closure#1}, alloc_fail::ring_buf::EvenU64, core::alloc::AllocError>> Line | Count | Source | 1236 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1237 | 1 | where | 1238 | 1 | E: From<AllocError>, | 1239 | 1 | { | 1240 | 1 | let mut this = Box::try_new_uninit()?0 ; | 1241 | 1 | let slot = this.as_mut_ptr(); | 1242 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1243 | 1 | // slot is valid and will not be moved, because we pin it later. | 1244 | 1 | unsafe { init.__pinned_init(slot)? }; | 1245 | | // SAFETY: All fields have been initialized. | 1246 | 0 | Ok(unsafe { this.assume_init() }.into()) | 1247 | 1 | } |
<alloc::boxed::Box<alloc_fail::ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::linked_list::ListHead>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::boxed::Box<alloc_fail::ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::mutex::linked_list::ListHead>::new::{closure#1}, alloc_fail::ring_buf::mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0}, alloc_fail::ring_buf::mutex::linked_list::ListHead, core::alloc::AllocError>> Line | Count | Source | 1236 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1237 | 1 | where | 1238 | 1 | E: From<AllocError>, | 1239 | 1 | { | 1240 | 1 | let mut this = Box::try_new_uninit()?0 ; | 1241 | 1 | let slot = this.as_mut_ptr(); | 1242 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1243 | 1 | // slot is valid and will not be moved, because we pin it later. | 1244 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1245 | | // SAFETY: All fields have been initialized. | 1246 | 1 | Ok(unsafe { this.assume_init() }.into()) | 1247 | 1 | } |
Unexecuted instantiation: <alloc::boxed::Box<_> as pinned_init::InPlaceInit<_>>::try_pin_init::<_, _> Unexecuted instantiation: <alloc::boxed::Box<_> as pinned_init::InPlaceInit<_>>::try_pin_init::<_, _> <alloc::boxed::Box<ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<ring_buf::mutex::linked_list::ListHead>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::boxed::Box<ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<ring_buf::mutex::linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<ring_buf::mutex::linked_list::ListHead>::insert_next::{closure#1}, ring_buf::mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0}, ring_buf::mutex::linked_list::ListHead, core::alloc::AllocError>> Line | Count | Source | 1236 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1237 | 1 | where | 1238 | 1 | E: From<AllocError>, | 1239 | 1 | { | 1240 | 1 | let mut this = Box::try_new_uninit()?0 ; | 1241 | 1 | let slot = this.as_mut_ptr(); | 1242 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1243 | 1 | // slot is valid and will not be moved, because we pin it later. | 1244 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1245 | | // SAFETY: All fields have been initialized. | 1246 | 1 | Ok(unsafe { this.assume_init() }.into()) | 1247 | 1 | } |
<alloc::boxed::Box<ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>> as pinned_init::InPlaceInit<ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::boxed::Box<ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>> as pinned_init::InPlaceInit<ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>>>::pin_init<pinned_init::__internal::InitClosure<<ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>>::new::{closure#1}, ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>, core::convert::Infallible>>::{closure#0}, ring_buf::RingBuffer<ring_buf::EvenU64, 4usize>, core::alloc::AllocError>> Line | Count | Source | 1236 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1237 | 1 | where | 1238 | 1 | E: From<AllocError>, | 1239 | 1 | { | 1240 | 1 | let mut this = Box::try_new_uninit()?0 ; | 1241 | 1 | let slot = this.as_mut_ptr(); | 1242 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1243 | 1 | // slot is valid and will not be moved, because we pin it later. | 1244 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1245 | | // SAFETY: All fields have been initialized. | 1246 | 1 | Ok(unsafe { this.assume_init() }.into()) | 1247 | 1 | } |
<alloc::boxed::Box<ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<ring_buf::mutex::linked_list::ListHead>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::boxed::Box<ring_buf::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<ring_buf::mutex::linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<ring_buf::mutex::linked_list::ListHead>::new::{closure#1}, ring_buf::mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0}, ring_buf::mutex::linked_list::ListHead, core::alloc::AllocError>> Line | Count | Source | 1236 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1237 | 1 | where | 1238 | 1 | E: From<AllocError>, | 1239 | 1 | { | 1240 | 1 | let mut this = Box::try_new_uninit()?0 ; | 1241 | 1 | let slot = this.as_mut_ptr(); | 1242 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1243 | 1 | // slot is valid and will not be moved, because we pin it later. | 1244 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1245 | | // SAFETY: All fields have been initialized. | 1246 | 1 | Ok(unsafe { this.assume_init() }.into()) | 1247 | 1 | } |
<alloc::boxed::Box<ring_buf::EvenU64> as pinned_init::InPlaceInit<ring_buf::EvenU64>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<ring_buf::EvenU64>::new2::{closure#1}, ring_buf::EvenU64, core::alloc::AllocError>> Line | Count | Source | 1236 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1237 | 1 | where | 1238 | 1 | E: From<AllocError>, | 1239 | 1 | { | 1240 | 1 | let mut this = Box::try_new_uninit()?0 ; | 1241 | 1 | let slot = this.as_mut_ptr(); | 1242 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1243 | 1 | // slot is valid and will not be moved, because we pin it later. | 1244 | 1 | unsafe { init.__pinned_init(slot)? }; | 1245 | | // SAFETY: All fields have been initialized. | 1246 | 0 | Ok(unsafe { this.assume_init() }.into()) | 1247 | 1 | } |
<alloc::boxed::Box<linked_list::ListHead> as pinned_init::InPlaceInit<linked_list::ListHead>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::boxed::Box<linked_list::ListHead> as pinned_init::InPlaceInit<linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<linked_list::ListHead>::new::{closure#1}, linked_list::ListHead, core::convert::Infallible>>::{closure#0}, linked_list::ListHead, core::alloc::AllocError>> Line | Count | Source | 1236 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1237 | 1 | where | 1238 | 1 | E: From<AllocError>, | 1239 | 1 | { | 1240 | 1 | let mut this = Box::try_new_uninit()?0 ; | 1241 | 1 | let slot = this.as_mut_ptr(); | 1242 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1243 | 1 | // slot is valid and will not be moved, because we pin it later. | 1244 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1245 | | // SAFETY: All fields have been initialized. | 1246 | 1 | Ok(unsafe { this.assume_init() }.into()) | 1247 | 1 | } |
<alloc::boxed::Box<linked_list::ListHead> as pinned_init::InPlaceInit<linked_list::ListHead>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::boxed::Box<linked_list::ListHead> as pinned_init::InPlaceInit<linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<linked_list::ListHead>::insert_next::{closure#1}, linked_list::ListHead, core::convert::Infallible>>::{closure#0}, linked_list::ListHead, core::alloc::AllocError>> Line | Count | Source | 1236 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1237 | 1 | where | 1238 | 1 | E: From<AllocError>, | 1239 | 1 | { | 1240 | 1 | let mut this = Box::try_new_uninit()?0 ; | 1241 | 1 | let slot = this.as_mut_ptr(); | 1242 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1243 | 1 | // slot is valid and will not be moved, because we pin it later. | 1244 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1245 | | // SAFETY: All fields have been initialized. | 1246 | 1 | Ok(unsafe { this.assume_init() }.into()) | 1247 | 1 | } |
<alloc::boxed::Box<mutex::linked_list::ListHead> as pinned_init::InPlaceInit<mutex::linked_list::ListHead>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::boxed::Box<mutex::linked_list::ListHead> as pinned_init::InPlaceInit<mutex::linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<mutex::linked_list::ListHead>::insert_next::{closure#1}, mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0}, mutex::linked_list::ListHead, core::alloc::AllocError>> Line | Count | Source | 1236 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1237 | 1 | where | 1238 | 1 | E: From<AllocError>, | 1239 | 1 | { | 1240 | 1 | let mut this = Box::try_new_uninit()?0 ; | 1241 | 1 | let slot = this.as_mut_ptr(); | 1242 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1243 | 1 | // slot is valid and will not be moved, because we pin it later. | 1244 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1245 | | // SAFETY: All fields have been initialized. | 1246 | 1 | Ok(unsafe { this.assume_init() }.into()) | 1247 | 1 | } |
<alloc::boxed::Box<mutex::linked_list::ListHead> as pinned_init::InPlaceInit<mutex::linked_list::ListHead>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::boxed::Box<mutex::linked_list::ListHead> as pinned_init::InPlaceInit<mutex::linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<mutex::linked_list::ListHead>::new::{closure#1}, mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0}, mutex::linked_list::ListHead, core::alloc::AllocError>> Line | Count | Source | 1236 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1237 | 1 | where | 1238 | 1 | E: From<AllocError>, | 1239 | 1 | { | 1240 | 1 | let mut this = Box::try_new_uninit()?0 ; | 1241 | 1 | let slot = this.as_mut_ptr(); | 1242 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1243 | 1 | // slot is valid and will not be moved, because we pin it later. | 1244 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1245 | | // SAFETY: All fields have been initialized. | 1246 | 1 | Ok(unsafe { this.assume_init() }.into()) | 1247 | 1 | } |
<alloc::boxed::Box<static_init::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<static_init::mutex::linked_list::ListHead>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::boxed::Box<static_init::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<static_init::mutex::linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<static_init::mutex::linked_list::ListHead>::new::{closure#1}, static_init::mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0}, static_init::mutex::linked_list::ListHead, core::alloc::AllocError>> Line | Count | Source | 1236 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1237 | 1 | where | 1238 | 1 | E: From<AllocError>, | 1239 | 1 | { | 1240 | 1 | let mut this = Box::try_new_uninit()?0 ; | 1241 | 1 | let slot = this.as_mut_ptr(); | 1242 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1243 | 1 | // slot is valid and will not be moved, because we pin it later. | 1244 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1245 | | // SAFETY: All fields have been initialized. | 1246 | 1 | Ok(unsafe { this.assume_init() }.into()) | 1247 | 1 | } |
<alloc::boxed::Box<static_init::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<static_init::mutex::linked_list::ListHead>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::boxed::Box<static_init::mutex::linked_list::ListHead> as pinned_init::InPlaceInit<static_init::mutex::linked_list::ListHead>>::pin_init<pinned_init::__internal::InitClosure<<static_init::mutex::linked_list::ListHead>::insert_next::{closure#1}, static_init::mutex::linked_list::ListHead, core::convert::Infallible>>::{closure#0}, static_init::mutex::linked_list::ListHead, core::alloc::AllocError>> Line | Count | Source | 1236 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1237 | 1 | where | 1238 | 1 | E: From<AllocError>, | 1239 | 1 | { | 1240 | 1 | let mut this = Box::try_new_uninit()?0 ; | 1241 | 1 | let slot = this.as_mut_ptr(); | 1242 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1243 | 1 | // slot is valid and will not be moved, because we pin it later. | 1244 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1245 | | // SAFETY: All fields have been initialized. | 1246 | 1 | Ok(unsafe { this.assume_init() }.into()) | 1247 | 1 | } |
|
1248 | | |
1249 | | #[inline] |
1250 | 5 | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E> |
1251 | 5 | where |
1252 | 5 | E: From<AllocError>, |
1253 | 5 | { |
1254 | 5 | let mut this4 = Box::try_new_uninit()?1 ; |
1255 | 4 | let slot = this.as_mut_ptr(); |
1256 | 4 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, |
1257 | 4 | // slot is valid. |
1258 | 4 | unsafe { init.__init(slot)?2 }; |
1259 | | // SAFETY: All fields have been initialized. |
1260 | 2 | Ok(unsafe { this.assume_init() }) |
1261 | 5 | } <alloc::boxed::Box<alloc_fail::ring_buf::EvenU64> as pinned_init::InPlaceInit<alloc_fail::ring_buf::EvenU64>>::try_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::EvenU64>::new2::{closure#1}, alloc_fail::ring_buf::EvenU64, core::alloc::AllocError>> Line | Count | Source | 1250 | 1 | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E> | 1251 | 1 | where | 1252 | 1 | E: From<AllocError>, | 1253 | 1 | { | 1254 | 1 | let mut this = Box::try_new_uninit()?0 ; | 1255 | 1 | let slot = this.as_mut_ptr(); | 1256 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1257 | 1 | // slot is valid. | 1258 | 1 | unsafe { init.__init(slot)? }; | 1259 | | // SAFETY: All fields have been initialized. | 1260 | 0 | Ok(unsafe { this.assume_init() }) | 1261 | 1 | } |
<alloc::boxed::Box<[u8; 1099511627776usize]> as pinned_init::InPlaceInit<[u8; 1099511627776usize]>>::try_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::boxed::Box<[u8; 1099511627776usize]> as pinned_init::InPlaceInit<[u8; 1099511627776usize]>>::init<pinned_init::__internal::InitClosure<pinned_init::zeroed<[u8; 1099511627776usize], core::convert::Infallible>::{closure#0}, [u8; 1099511627776usize], core::convert::Infallible>>::{closure#0}, [u8; 1099511627776usize], core::alloc::AllocError>> Line | Count | Source | 1250 | 1 | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E> | 1251 | 1 | where | 1252 | 1 | E: From<AllocError>, | 1253 | 1 | { | 1254 | 1 | let mut this0 = Box::try_new_uninit()?; | 1255 | 0 | let slot = this.as_mut_ptr(); | 1256 | 0 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1257 | 0 | // slot is valid. | 1258 | 0 | unsafe { init.__init(slot)? }; | 1259 | | // SAFETY: All fields have been initialized. | 1260 | 0 | Ok(unsafe { this.assume_init() }) | 1261 | 1 | } |
<alloc::boxed::Box<alloc_fail::ring_buf::BigStruct> as pinned_init::InPlaceInit<alloc_fail::ring_buf::BigStruct>>::try_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::boxed::Box<alloc_fail::ring_buf::BigStruct> as pinned_init::InPlaceInit<alloc_fail::ring_buf::BigStruct>>::init<pinned_init::__internal::InitClosure<alloc_fail::ring_buf::big_struct::{closure#3}, alloc_fail::ring_buf::BigStruct, core::convert::Infallible>>::{closure#0}, alloc_fail::ring_buf::BigStruct, core::alloc::AllocError>> Line | Count | Source | 1250 | 1 | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E> | 1251 | 1 | where | 1252 | 1 | E: From<AllocError>, | 1253 | 1 | { | 1254 | 1 | let mut this = Box::try_new_uninit()?0 ; | 1255 | 1 | let slot = this.as_mut_ptr(); | 1256 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1257 | 1 | // slot is valid. | 1258 | 1 | unsafe { init.__init(slot)?0 }; | 1259 | | // SAFETY: All fields have been initialized. | 1260 | 1 | Ok(unsafe { this.assume_init() }) | 1261 | 1 | } |
Unexecuted instantiation: <alloc::boxed::Box<_> as pinned_init::InPlaceInit<_>>::try_init::<_, _> Unexecuted instantiation: <alloc::boxed::Box<_> as pinned_init::InPlaceInit<_>>::try_init::<_, _> <alloc::boxed::Box<ring_buf::BigStruct> as pinned_init::InPlaceInit<ring_buf::BigStruct>>::try_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::boxed::Box<ring_buf::BigStruct> as pinned_init::InPlaceInit<ring_buf::BigStruct>>::init<pinned_init::__internal::InitClosure<ring_buf::big_struct::{closure#3}, ring_buf::BigStruct, core::convert::Infallible>>::{closure#0}, ring_buf::BigStruct, core::alloc::AllocError>> Line | Count | Source | 1250 | 1 | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E> | 1251 | 1 | where | 1252 | 1 | E: From<AllocError>, | 1253 | 1 | { | 1254 | 1 | let mut this = Box::try_new_uninit()?0 ; | 1255 | 1 | let slot = this.as_mut_ptr(); | 1256 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1257 | 1 | // slot is valid. | 1258 | 1 | unsafe { init.__init(slot)?0 }; | 1259 | | // SAFETY: All fields have been initialized. | 1260 | 1 | Ok(unsafe { this.assume_init() }) | 1261 | 1 | } |
<alloc::boxed::Box<ring_buf::EvenU64> as pinned_init::InPlaceInit<ring_buf::EvenU64>>::try_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<ring_buf::EvenU64>::new2::{closure#1}, ring_buf::EvenU64, core::alloc::AllocError>> Line | Count | Source | 1250 | 1 | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E> | 1251 | 1 | where | 1252 | 1 | E: From<AllocError>, | 1253 | 1 | { | 1254 | 1 | let mut this = Box::try_new_uninit()?0 ; | 1255 | 1 | let slot = this.as_mut_ptr(); | 1256 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1257 | 1 | // slot is valid. | 1258 | 1 | unsafe { init.__init(slot)? }; | 1259 | | // SAFETY: All fields have been initialized. | 1260 | 0 | Ok(unsafe { this.assume_init() }) | 1261 | 1 | } |
|
1262 | | } |
1263 | | |
1264 | | #[cfg(any(feature = "alloc"))] |
1265 | | impl<T> InPlaceInit<T> for Arc<T> { |
1266 | | #[inline] |
1267 | 10 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> |
1268 | 10 | where |
1269 | 10 | E: From<AllocError>, |
1270 | 10 | { |
1271 | 10 | let mut this9 = Arc::try_new_uninit()?1 ; |
1272 | 9 | let slot = unsafe { Arc::get_mut_unchecked(&mut this) }; |
1273 | 9 | let slot = slot.as_mut_ptr(); |
1274 | 9 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, |
1275 | 9 | // slot is valid and will not be moved, because we pin it later. |
1276 | 9 | unsafe { init.__pinned_init(slot)?2 }; |
1277 | | // SAFETY: All fields have been initialized and this is the only `Arc` to that data. |
1278 | 7 | Ok(unsafe { Pin::new_unchecked(this.assume_init()) }) |
1279 | 10 | } <alloc::sync::Arc<alloc_fail::ring_buf::mutex::CMutex<usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::CMutex<usize>>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::sync::Arc<alloc_fail::ring_buf::mutex::CMutex<usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::CMutex<usize>>>::pin_init<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::mutex::CMutex<usize>>::new<usize>::{closure#1}, alloc_fail::ring_buf::mutex::CMutex<usize>, core::convert::Infallible>>::{closure#0}, alloc_fail::ring_buf::mutex::CMutex<usize>, core::alloc::AllocError>> Line | Count | Source | 1267 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1268 | 1 | where | 1269 | 1 | E: From<AllocError>, | 1270 | 1 | { | 1271 | 1 | let mut this = Arc::try_new_uninit()?0 ; | 1272 | 1 | let slot = unsafe { Arc::get_mut_unchecked(&mut this) }; | 1273 | 1 | let slot = slot.as_mut_ptr(); | 1274 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1275 | 1 | // slot is valid and will not be moved, because we pin it later. | 1276 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1277 | | // SAFETY: All fields have been initialized and this is the only `Arc` to that data. | 1278 | 1 | Ok(unsafe { Pin::new_unchecked(this.assume_init()) }) | 1279 | 1 | } |
<alloc::sync::Arc<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::sync::Arc<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>>::pin_init<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>>::new::{closure#1}, alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>, core::convert::Infallible>>::{closure#0}, alloc_fail::ring_buf::RingBuffer<u8, 1099511627776usize>, core::alloc::AllocError>> Line | Count | Source | 1267 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1268 | 1 | where | 1269 | 1 | E: From<AllocError>, | 1270 | 1 | { | 1271 | 1 | let mut this0 = Arc::try_new_uninit()?; | 1272 | 0 | let slot = unsafe { Arc::get_mut_unchecked(&mut this) }; | 1273 | 0 | let slot = slot.as_mut_ptr(); | 1274 | 0 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1275 | 0 | // slot is valid and will not be moved, because we pin it later. | 1276 | 0 | unsafe { init.__pinned_init(slot)? }; | 1277 | | // SAFETY: All fields have been initialized and this is the only `Arc` to that data. | 1278 | 0 | Ok(unsafe { Pin::new_unchecked(this.assume_init()) }) | 1279 | 1 | } |
<alloc::sync::Arc<alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::sync::Arc<alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>> as pinned_init::InPlaceInit<alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>>>::pin_init<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>>::new<pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>::new::{closure#1}, alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>, core::convert::Infallible>>::{closure#1}, alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>, core::convert::Infallible>>::{closure#0}, alloc_fail::ring_buf::mutex::CMutex<alloc_fail::ring_buf::RingBuffer<alloc_fail::ring_buf::BigStruct, 64usize>>, core::alloc::AllocError>> Line | Count | Source | 1267 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1268 | 1 | where | 1269 | 1 | E: From<AllocError>, | 1270 | 1 | { | 1271 | 1 | let mut this = Arc::try_new_uninit()?0 ; | 1272 | 1 | let slot = unsafe { Arc::get_mut_unchecked(&mut this) }; | 1273 | 1 | let slot = slot.as_mut_ptr(); | 1274 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1275 | 1 | // slot is valid and will not be moved, because we pin it later. | 1276 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1277 | | // SAFETY: All fields have been initialized and this is the only `Arc` to that data. | 1278 | 1 | Ok(unsafe { Pin::new_unchecked(this.assume_init()) }) | 1279 | 1 | } |
<alloc::sync::Arc<alloc_fail::ring_buf::EvenU64> as pinned_init::InPlaceInit<alloc_fail::ring_buf::EvenU64>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::EvenU64>::new2::{closure#1}, alloc_fail::ring_buf::EvenU64, core::alloc::AllocError>> Line | Count | Source | 1267 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1268 | 1 | where | 1269 | 1 | E: From<AllocError>, | 1270 | 1 | { | 1271 | 1 | let mut this = Arc::try_new_uninit()?0 ; | 1272 | 1 | let slot = unsafe { Arc::get_mut_unchecked(&mut this) }; | 1273 | 1 | let slot = slot.as_mut_ptr(); | 1274 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1275 | 1 | // slot is valid and will not be moved, because we pin it later. | 1276 | 1 | unsafe { init.__pinned_init(slot)? }; | 1277 | | // SAFETY: All fields have been initialized and this is the only `Arc` to that data. | 1278 | 0 | Ok(unsafe { Pin::new_unchecked(this.assume_init()) }) | 1279 | 1 | } |
Unexecuted instantiation: <alloc::sync::Arc<_> as pinned_init::InPlaceInit<_>>::try_pin_init::<_, _> Unexecuted instantiation: <alloc::sync::Arc<_> as pinned_init::InPlaceInit<_>>::try_pin_init::<_, _> <alloc::sync::Arc<ring_buf::EvenU64> as pinned_init::InPlaceInit<ring_buf::EvenU64>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<ring_buf::EvenU64>::new2::{closure#1}, ring_buf::EvenU64, core::alloc::AllocError>> Line | Count | Source | 1267 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1268 | 1 | where | 1269 | 1 | E: From<AllocError>, | 1270 | 1 | { | 1271 | 1 | let mut this = Arc::try_new_uninit()?0 ; | 1272 | 1 | let slot = unsafe { Arc::get_mut_unchecked(&mut this) }; | 1273 | 1 | let slot = slot.as_mut_ptr(); | 1274 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1275 | 1 | // slot is valid and will not be moved, because we pin it later. | 1276 | 1 | unsafe { init.__pinned_init(slot)? }; | 1277 | | // SAFETY: All fields have been initialized and this is the only `Arc` to that data. | 1278 | 0 | Ok(unsafe { Pin::new_unchecked(this.assume_init()) }) | 1279 | 1 | } |
<alloc::sync::Arc<ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>> as pinned_init::InPlaceInit<ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::sync::Arc<ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>> as pinned_init::InPlaceInit<ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>>>::pin_init<pinned_init::__internal::InitClosure<<ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>>::new<pinned_init::__internal::InitClosure<<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>::new::{closure#1}, ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>, core::convert::Infallible>>::{closure#1}, ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>, core::convert::Infallible>>::{closure#0}, ring_buf::mutex::CMutex<ring_buf::RingBuffer<ring_buf::BigStruct, 64usize>>, core::alloc::AllocError>> Line | Count | Source | 1267 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1268 | 1 | where | 1269 | 1 | E: From<AllocError>, | 1270 | 1 | { | 1271 | 1 | let mut this = Arc::try_new_uninit()?0 ; | 1272 | 1 | let slot = unsafe { Arc::get_mut_unchecked(&mut this) }; | 1273 | 1 | let slot = slot.as_mut_ptr(); | 1274 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1275 | 1 | // slot is valid and will not be moved, because we pin it later. | 1276 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1277 | | // SAFETY: All fields have been initialized and this is the only `Arc` to that data. | 1278 | 1 | Ok(unsafe { Pin::new_unchecked(this.assume_init()) }) | 1279 | 1 | } |
<alloc::sync::Arc<ring_buf::mutex::CMutex<usize>> as pinned_init::InPlaceInit<ring_buf::mutex::CMutex<usize>>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::sync::Arc<ring_buf::mutex::CMutex<usize>> as pinned_init::InPlaceInit<ring_buf::mutex::CMutex<usize>>>::pin_init<pinned_init::__internal::InitClosure<<ring_buf::mutex::CMutex<usize>>::new<usize>::{closure#1}, ring_buf::mutex::CMutex<usize>, core::convert::Infallible>>::{closure#0}, ring_buf::mutex::CMutex<usize>, core::alloc::AllocError>> Line | Count | Source | 1267 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1268 | 1 | where | 1269 | 1 | E: From<AllocError>, | 1270 | 1 | { | 1271 | 1 | let mut this = Arc::try_new_uninit()?0 ; | 1272 | 1 | let slot = unsafe { Arc::get_mut_unchecked(&mut this) }; | 1273 | 1 | let slot = slot.as_mut_ptr(); | 1274 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1275 | 1 | // slot is valid and will not be moved, because we pin it later. | 1276 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1277 | | // SAFETY: All fields have been initialized and this is the only `Arc` to that data. | 1278 | 1 | Ok(unsafe { Pin::new_unchecked(this.assume_init()) }) | 1279 | 1 | } |
<alloc::sync::Arc<mutex::CMutex<usize>> as pinned_init::InPlaceInit<mutex::CMutex<usize>>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::sync::Arc<mutex::CMutex<usize>> as pinned_init::InPlaceInit<mutex::CMutex<usize>>>::pin_init<pinned_init::__internal::InitClosure<<mutex::CMutex<usize>>::new<usize>::{closure#1}, mutex::CMutex<usize>, core::convert::Infallible>>::{closure#0}, mutex::CMutex<usize>, core::alloc::AllocError>> Line | Count | Source | 1267 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1268 | 1 | where | 1269 | 1 | E: From<AllocError>, | 1270 | 1 | { | 1271 | 1 | let mut this = Arc::try_new_uninit()?0 ; | 1272 | 1 | let slot = unsafe { Arc::get_mut_unchecked(&mut this) }; | 1273 | 1 | let slot = slot.as_mut_ptr(); | 1274 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1275 | 1 | // slot is valid and will not be moved, because we pin it later. | 1276 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1277 | | // SAFETY: All fields have been initialized and this is the only `Arc` to that data. | 1278 | 1 | Ok(unsafe { Pin::new_unchecked(this.assume_init()) }) | 1279 | 1 | } |
<alloc::sync::Arc<pthread_mutex::pthread_mtx::PThreadMutex<usize>> as pinned_init::InPlaceInit<pthread_mutex::pthread_mtx::PThreadMutex<usize>>>::try_pin_init::<pthread_mutex::pthread_mtx::Error, pinned_init::__internal::InitClosure<<pthread_mutex::pthread_mtx::PThreadMutex<usize>>::new::{closure#1}, pthread_mutex::pthread_mtx::PThreadMutex<usize>, pthread_mutex::pthread_mtx::Error>> Line | Count | Source | 1267 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1268 | 1 | where | 1269 | 1 | E: From<AllocError>, | 1270 | 1 | { | 1271 | 1 | let mut this = Arc::try_new_uninit()?0 ; | 1272 | 1 | let slot = unsafe { Arc::get_mut_unchecked(&mut this) }; | 1273 | 1 | let slot = slot.as_mut_ptr(); | 1274 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1275 | 1 | // slot is valid and will not be moved, because we pin it later. | 1276 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1277 | | // SAFETY: All fields have been initialized and this is the only `Arc` to that data. | 1278 | 1 | Ok(unsafe { Pin::new_unchecked(this.assume_init()) }) | 1279 | 1 | } |
<alloc::sync::Arc<static_init::mutex::CMutex<usize>> as pinned_init::InPlaceInit<static_init::mutex::CMutex<usize>>>::try_pin_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::sync::Arc<static_init::mutex::CMutex<usize>> as pinned_init::InPlaceInit<static_init::mutex::CMutex<usize>>>::pin_init<pinned_init::__internal::InitClosure<<static_init::mutex::CMutex<usize>>::new<usize>::{closure#1}, static_init::mutex::CMutex<usize>, core::convert::Infallible>>::{closure#0}, static_init::mutex::CMutex<usize>, core::alloc::AllocError>> Line | Count | Source | 1267 | 1 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E> | 1268 | 1 | where | 1269 | 1 | E: From<AllocError>, | 1270 | 1 | { | 1271 | 1 | let mut this = Arc::try_new_uninit()?0 ; | 1272 | 1 | let slot = unsafe { Arc::get_mut_unchecked(&mut this) }; | 1273 | 1 | let slot = slot.as_mut_ptr(); | 1274 | 1 | // SAFETY: When init errors/panics, slot will get deallocated but not dropped, | 1275 | 1 | // slot is valid and will not be moved, because we pin it later. | 1276 | 1 | unsafe { init.__pinned_init(slot)?0 }; | 1277 | | // SAFETY: All fields have been initialized and this is the only `Arc` to that data. | 1278 | 1 | Ok(unsafe { Pin::new_unchecked(this.assume_init()) }) | 1279 | 1 | } |
|
1280 | | |
1281 | | #[inline] |
1282 | 5 | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E> |
1283 | 5 | where |
1284 | 5 | E: From<AllocError>, |
1285 | 5 | { |
1286 | 5 | let mut this4 = Arc::try_new_uninit()?1 ; |
1287 | 4 | let slot = unsafe { Arc::get_mut_unchecked(&mut this) }; |
1288 | 4 | let slot = slot.as_mut_ptr(); |
1289 | 4 | // SAFETY: when init errors/panics, slot will get deallocated but not dropped, |
1290 | 4 | // slot is valid. |
1291 | 4 | unsafe { init.__init(slot)?2 }; |
1292 | | // SAFETY: All fields have been initialized. |
1293 | 2 | Ok(unsafe { this.assume_init() }) |
1294 | 5 | } <alloc::sync::Arc<alloc_fail::ring_buf::EvenU64> as pinned_init::InPlaceInit<alloc_fail::ring_buf::EvenU64>>::try_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc_fail::ring_buf::EvenU64>::new2::{closure#1}, alloc_fail::ring_buf::EvenU64, core::alloc::AllocError>> Line | Count | Source | 1282 | 1 | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E> | 1283 | 1 | where | 1284 | 1 | E: From<AllocError>, | 1285 | 1 | { | 1286 | 1 | let mut this = Arc::try_new_uninit()?0 ; | 1287 | 1 | let slot = unsafe { Arc::get_mut_unchecked(&mut this) }; | 1288 | 1 | let slot = slot.as_mut_ptr(); | 1289 | 1 | // SAFETY: when init errors/panics, slot will get deallocated but not dropped, | 1290 | 1 | // slot is valid. | 1291 | 1 | unsafe { init.__init(slot)? }; | 1292 | | // SAFETY: All fields have been initialized. | 1293 | 0 | Ok(unsafe { this.assume_init() }) | 1294 | 1 | } |
<alloc::sync::Arc<alloc_fail::ring_buf::BigStruct> as pinned_init::InPlaceInit<alloc_fail::ring_buf::BigStruct>>::try_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::sync::Arc<alloc_fail::ring_buf::BigStruct> as pinned_init::InPlaceInit<alloc_fail::ring_buf::BigStruct>>::init<pinned_init::__internal::InitClosure<alloc_fail::ring_buf::big_struct::{closure#1}, alloc_fail::ring_buf::BigStruct, core::convert::Infallible>>::{closure#0}, alloc_fail::ring_buf::BigStruct, core::alloc::AllocError>> Line | Count | Source | 1282 | 1 | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E> | 1283 | 1 | where | 1284 | 1 | E: From<AllocError>, | 1285 | 1 | { | 1286 | 1 | let mut this = Arc::try_new_uninit()?0 ; | 1287 | 1 | let slot = unsafe { Arc::get_mut_unchecked(&mut this) }; | 1288 | 1 | let slot = slot.as_mut_ptr(); | 1289 | 1 | // SAFETY: when init errors/panics, slot will get deallocated but not dropped, | 1290 | 1 | // slot is valid. | 1291 | 1 | unsafe { init.__init(slot)?0 }; | 1292 | | // SAFETY: All fields have been initialized. | 1293 | 1 | Ok(unsafe { this.assume_init() }) | 1294 | 1 | } |
<alloc::sync::Arc<[u8; 1099511627776usize]> as pinned_init::InPlaceInit<[u8; 1099511627776usize]>>::try_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::sync::Arc<[u8; 1099511627776usize]> as pinned_init::InPlaceInit<[u8; 1099511627776usize]>>::init<pinned_init::__internal::InitClosure<pinned_init::zeroed<[u8; 1099511627776usize], core::convert::Infallible>::{closure#0}, [u8; 1099511627776usize], core::convert::Infallible>>::{closure#0}, [u8; 1099511627776usize], core::alloc::AllocError>> Line | Count | Source | 1282 | 1 | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E> | 1283 | 1 | where | 1284 | 1 | E: From<AllocError>, | 1285 | 1 | { | 1286 | 1 | let mut this0 = Arc::try_new_uninit()?; | 1287 | 0 | let slot = unsafe { Arc::get_mut_unchecked(&mut this) }; | 1288 | 0 | let slot = slot.as_mut_ptr(); | 1289 | 0 | // SAFETY: when init errors/panics, slot will get deallocated but not dropped, | 1290 | 0 | // slot is valid. | 1291 | 0 | unsafe { init.__init(slot)? }; | 1292 | | // SAFETY: All fields have been initialized. | 1293 | 0 | Ok(unsafe { this.assume_init() }) | 1294 | 1 | } |
Unexecuted instantiation: <alloc::sync::Arc<_> as pinned_init::InPlaceInit<_>>::try_init::<_, _> Unexecuted instantiation: <alloc::sync::Arc<_> as pinned_init::InPlaceInit<_>>::try_init::<_, _> <alloc::sync::Arc<ring_buf::BigStruct> as pinned_init::InPlaceInit<ring_buf::BigStruct>>::try_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<alloc::sync::Arc<ring_buf::BigStruct> as pinned_init::InPlaceInit<ring_buf::BigStruct>>::init<pinned_init::__internal::InitClosure<ring_buf::big_struct::{closure#1}, ring_buf::BigStruct, core::convert::Infallible>>::{closure#0}, ring_buf::BigStruct, core::alloc::AllocError>> Line | Count | Source | 1282 | 1 | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E> | 1283 | 1 | where | 1284 | 1 | E: From<AllocError>, | 1285 | 1 | { | 1286 | 1 | let mut this = Arc::try_new_uninit()?0 ; | 1287 | 1 | let slot = unsafe { Arc::get_mut_unchecked(&mut this) }; | 1288 | 1 | let slot = slot.as_mut_ptr(); | 1289 | 1 | // SAFETY: when init errors/panics, slot will get deallocated but not dropped, | 1290 | 1 | // slot is valid. | 1291 | 1 | unsafe { init.__init(slot)?0 }; | 1292 | | // SAFETY: All fields have been initialized. | 1293 | 1 | Ok(unsafe { this.assume_init() }) | 1294 | 1 | } |
<alloc::sync::Arc<ring_buf::EvenU64> as pinned_init::InPlaceInit<ring_buf::EvenU64>>::try_init::<core::alloc::AllocError, pinned_init::__internal::InitClosure<<ring_buf::EvenU64>::new2::{closure#1}, ring_buf::EvenU64, core::alloc::AllocError>> Line | Count | Source | 1282 | 1 | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E> | 1283 | 1 | where | 1284 | 1 | E: From<AllocError>, | 1285 | 1 | { | 1286 | 1 | let mut this = Arc::try_new_uninit()?0 ; | 1287 | 1 | let slot = unsafe { Arc::get_mut_unchecked(&mut this) }; | 1288 | 1 | let slot = slot.as_mut_ptr(); | 1289 | 1 | // SAFETY: when init errors/panics, slot will get deallocated but not dropped, | 1290 | 1 | // slot is valid. | 1291 | 1 | unsafe { init.__init(slot)? }; | 1292 | | // SAFETY: All fields have been initialized. | 1293 | 0 | Ok(unsafe { this.assume_init() }) | 1294 | 1 | } |
|
1295 | | } |
1296 | | |
1297 | | /// Trait facilitating pinned destruction. |
1298 | | /// |
1299 | | /// Use [`pinned_drop`] to implement this trait safely: |
1300 | | /// |
1301 | | /// ```rust |
1302 | | /// # #![feature(allocator_api, no_coverage)] |
1303 | | /// # #[path = "../examples/mutex.rs"] mod mutex; use mutex::*; |
1304 | | /// use pinned_init::*; |
1305 | | /// use core::pin::Pin; |
1306 | | /// #[pin_data(PinnedDrop)] |
1307 | | /// struct Foo { |
1308 | | /// #[pin] |
1309 | | /// mtx: CMutex<usize>, |
1310 | | /// } |
1311 | | /// |
1312 | | /// #[pinned_drop] |
1313 | | /// impl PinnedDrop for Foo { |
1314 | | /// fn drop(self: Pin<&mut Self>) { |
1315 | | /// println!("Foo is being dropped!"); |
1316 | | /// } |
1317 | | /// } |
1318 | | /// # let _ = Box::pin_init(pin_init!(Foo { mtx <- CMutex::new(0) })); |
1319 | | /// ``` |
1320 | | /// |
1321 | | /// # Safety |
1322 | | /// |
1323 | | /// This trait must be implemented via the [`pinned_drop`] proc-macro attribute on the impl. |
1324 | | /// |
1325 | | /// [`pinned_drop`]: pinned_init_macro::pinned_drop |
1326 | | pub unsafe trait PinnedDrop: __internal::HasPinData { |
1327 | | /// Executes the pinned destructor of this type. |
1328 | | /// |
1329 | | /// While this function is marked safe, it is actually unsafe to call it manually. For this |
1330 | | /// reason it takes an additional parameter. This type can only be constructed by `unsafe` code |
1331 | | /// and thus prevents this function from being called where it should not. |
1332 | | /// |
1333 | | /// This extra parameter will be generated by the `#[pinned_drop]` proc-macro attribute |
1334 | | /// automatically. |
1335 | | fn drop(self: Pin<&mut Self>, only_call_from_drop: __internal::OnlyCallFromDrop); |
1336 | | } |
1337 | | |
1338 | | /// Marker trait for types that can be initialized by writing just zeroes. |
1339 | | /// |
1340 | | /// # Safety |
1341 | | /// |
1342 | | /// The bit pattern consisting of only zeroes is a valid bit pattern for this type. In other words, |
1343 | | /// this is not UB: |
1344 | | /// |
1345 | | /// ```rust,ignore |
1346 | | /// let val: Self = unsafe { core::mem::zeroed() }; |
1347 | | /// ``` |
1348 | | pub unsafe trait Zeroable {} |
1349 | | |
1350 | | /// Create a new zeroed T. |
1351 | | /// |
1352 | | /// The returned initializer will write `0x00` to every byte of the given `slot`. |
1353 | | #[inline] |
1354 | 136 | pub fn zeroed<T: Zeroable, E>() -> impl Init<T, E> { |
1355 | 136 | // SAFETY: Because `T: Zeroable`, all bytes zero is a valid bit pattern for `T` |
1356 | 136 | // and because we write all zeroes, the memory is initialized. |
1357 | 136 | unsafe { |
1358 | 136 | init_from_closure(|slot: *mut T| { |
1359 | 134 | slot.write_bytes(0, 1); |
1360 | 134 | Ok(()) |
1361 | 136 | }) Unexecuted instantiation: pinned_init::zeroed::<[u8; 1099511627776usize], core::convert::Infallible>::{closure#0} pinned_init::zeroed::<[u8; 1048576usize], core::convert::Infallible>::{closure#0} Line | Count | Source | 1358 | 65 | init_from_closure(|slot: *mut T| { | 1359 | 65 | slot.write_bytes(0, 1); | 1360 | 65 | Ok(()) | 1361 | 65 | }) |
pinned_init::zeroed::<core::mem::maybe_uninit::MaybeUninit<u8>, core::convert::Infallible>::{closure#0} Line | Count | Source | 1358 | 2 | init_from_closure(|slot: *mut T| { | 1359 | 2 | slot.write_bytes(0, 1); | 1360 | 2 | Ok(()) | 1361 | 2 | }) |
Unexecuted instantiation: pinned_init::zeroed::<_, _>::{closure#0} Unexecuted instantiation: pinned_init::zeroed::<_, _>::{closure#0} pinned_init::zeroed::<core::mem::maybe_uninit::MaybeUninit<u8>, core::convert::Infallible>::{closure#0} Line | Count | Source | 1358 | 2 | init_from_closure(|slot: *mut T| { | 1359 | 2 | slot.write_bytes(0, 1); | 1360 | 2 | Ok(()) | 1361 | 2 | }) |
pinned_init::zeroed::<[u8; 1048576usize], core::convert::Infallible>::{closure#0} Line | Count | Source | 1358 | 65 | init_from_closure(|slot: *mut T| { | 1359 | 65 | slot.write_bytes(0, 1); | 1360 | 65 | Ok(()) | 1361 | 65 | }) |
|
1362 | 136 | } |
1363 | 136 | } pinned_init::zeroed::<[u8; 1099511627776usize], core::convert::Infallible> Line | Count | Source | 1354 | 2 | pub fn zeroed<T: Zeroable, E>() -> impl Init<T, E> { | 1355 | 2 | // SAFETY: Because `T: Zeroable`, all bytes zero is a valid bit pattern for `T` | 1356 | 2 | // and because we write all zeroes, the memory is initialized. | 1357 | 2 | unsafe { | 1358 | 2 | init_from_closure(|slot: *mut T| { | 1359 | | slot.write_bytes(0, 1); | 1360 | | Ok(()) | 1361 | 2 | }) | 1362 | 2 | } | 1363 | 2 | } |
pinned_init::zeroed::<core::mem::maybe_uninit::MaybeUninit<u8>, core::convert::Infallible> Line | Count | Source | 1354 | 2 | pub fn zeroed<T: Zeroable, E>() -> impl Init<T, E> { | 1355 | 2 | // SAFETY: Because `T: Zeroable`, all bytes zero is a valid bit pattern for `T` | 1356 | 2 | // and because we write all zeroes, the memory is initialized. | 1357 | 2 | unsafe { | 1358 | 2 | init_from_closure(|slot: *mut T| { | 1359 | | slot.write_bytes(0, 1); | 1360 | | Ok(()) | 1361 | 2 | }) | 1362 | 2 | } | 1363 | 2 | } |
pinned_init::zeroed::<[u8; 1048576usize], core::convert::Infallible> Line | Count | Source | 1354 | 65 | pub fn zeroed<T: Zeroable, E>() -> impl Init<T, E> { | 1355 | 65 | // SAFETY: Because `T: Zeroable`, all bytes zero is a valid bit pattern for `T` | 1356 | 65 | // and because we write all zeroes, the memory is initialized. | 1357 | 65 | unsafe { | 1358 | 65 | init_from_closure(|slot: *mut T| { | 1359 | | slot.write_bytes(0, 1); | 1360 | | Ok(()) | 1361 | 65 | }) | 1362 | 65 | } | 1363 | 65 | } |
Unexecuted instantiation: pinned_init::zeroed::<_, _> Unexecuted instantiation: pinned_init::zeroed::<_, _> pinned_init::zeroed::<core::mem::maybe_uninit::MaybeUninit<u8>, core::convert::Infallible> Line | Count | Source | 1354 | 2 | pub fn zeroed<T: Zeroable, E>() -> impl Init<T, E> { | 1355 | 2 | // SAFETY: Because `T: Zeroable`, all bytes zero is a valid bit pattern for `T` | 1356 | 2 | // and because we write all zeroes, the memory is initialized. | 1357 | 2 | unsafe { | 1358 | 2 | init_from_closure(|slot: *mut T| { | 1359 | | slot.write_bytes(0, 1); | 1360 | | Ok(()) | 1361 | 2 | }) | 1362 | 2 | } | 1363 | 2 | } |
pinned_init::zeroed::<[u8; 1048576usize], core::convert::Infallible> Line | Count | Source | 1354 | 65 | pub fn zeroed<T: Zeroable, E>() -> impl Init<T, E> { | 1355 | 65 | // SAFETY: Because `T: Zeroable`, all bytes zero is a valid bit pattern for `T` | 1356 | 65 | // and because we write all zeroes, the memory is initialized. | 1357 | 65 | unsafe { | 1358 | 65 | init_from_closure(|slot: *mut T| { | 1359 | | slot.write_bytes(0, 1); | 1360 | | Ok(()) | 1361 | 65 | }) | 1362 | 65 | } | 1363 | 65 | } |
|
1364 | | |
1365 | | macro_rules! impl_zeroable { |
1366 | | ($($(#[$attr:meta])*$({$($generics:tt)*})? $t:ty, )*) => { |
1367 | | $( |
1368 | | $(#[$attr])* |
1369 | | unsafe impl$($($generics)*)? Zeroable for $t {} |
1370 | | )* |
1371 | | }; |
1372 | | } |
1373 | | |
1374 | | impl_zeroable! { |
1375 | | // SAFETY: All primitives that are allowed to be zero. |
1376 | | bool, |
1377 | | char, |
1378 | | u8, u16, u32, u64, u128, usize, |
1379 | | i8, i16, i32, i64, i128, isize, |
1380 | | f32, f64, |
1381 | | |
1382 | | // SAFETY: These are ZSTs, there is nothing to zero. |
1383 | | {<T: ?Sized>} PhantomData<T>, core::marker::PhantomPinned, Infallible, (), |
1384 | | |
1385 | | // SAFETY: Type is allowed to take any value, including all zeros. |
1386 | | {<T>} MaybeUninit<T>, |
1387 | | |
1388 | | // SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee). |
1389 | | Option<NonZeroU8>, Option<NonZeroU16>, Option<NonZeroU32>, Option<NonZeroU64>, |
1390 | | Option<NonZeroU128>, Option<NonZeroUsize>, |
1391 | | Option<NonZeroI8>, Option<NonZeroI16>, Option<NonZeroI32>, Option<NonZeroI64>, |
1392 | | Option<NonZeroI128>, Option<NonZeroIsize>, |
1393 | | |
1394 | | // SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee). |
1395 | | // |
1396 | | // In this case we are allowed to use `T: ?Sized`, since all zeros is the `None` variant. |
1397 | | {<T: ?Sized>} Option<NonNull<T>>, |
1398 | | #[cfg(feature = "alloc")] |
1399 | | {<T: ?Sized>} Option<Box<T>>, |
1400 | | |
1401 | | // SAFETY: `null` pointer is valid. |
1402 | | // |
1403 | | // We cannot use `T: ?Sized`, since the VTABLE pointer part of fat pointers is not allowed to be |
1404 | | // null. |
1405 | | // |
1406 | | // When `Pointee` gets stabilized, we could use |
1407 | | // `T: ?Sized where <T as Pointee>::Metadata: Zeroable` |
1408 | | {<T>} *mut T, {<T>} *const T, |
1409 | | |
1410 | | // SAFETY: `null` pointer is valid and the metadata part of these fat pointers is allowed to be |
1411 | | // zero. |
1412 | | {<T>} *mut [T], {<T>} *const [T], *mut str, *const str, |
1413 | | |
1414 | | // SAFETY: `T` is `Zeroable`. |
1415 | | {<const N: usize, T: Zeroable>} [T; N], {<T: Zeroable>} Wrapping<T>, |
1416 | | } |
1417 | | |
1418 | | macro_rules! impl_tuple_zeroable { |
1419 | | ($(,)?) => {}; |
1420 | | ($first:ident, $($t:ident),* $(,)?) => { |
1421 | | // SAFETY: All elements are zeroable and padding can be zero. |
1422 | | unsafe impl<$first: Zeroable, $($t: Zeroable),*> Zeroable for ($first, $($t),*) {} |
1423 | | impl_tuple_zeroable!($($t),* ,); |
1424 | | } |
1425 | | } |
1426 | | |
1427 | | impl_tuple_zeroable!(A, B, C, D, E, F, G, H, I, J); |