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