| 1 | |
| 2 |
|
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 |
|
| 202 | use crate::{
|
| 203 | error::{self, Error},
|
| 204 | sync::UniqueArc,
|
| 205 | };
|
| 206 | use alloc::boxed::Box;
|
| 207 | use core::{
|
| 208 | alloc::AllocError,
|
| 209 | cell::Cell,
|
| 210 | convert::Infallible,
|
| 211 | marker::PhantomData,
|
| 212 | mem::MaybeUninit,
|
| 213 | num::*,
|
| 214 | pin::Pin,
|
| 215 | ptr::{self, NonNull},
|
| 216 | };
|
| 217 |
|
| 218 | #[doc(hidden)]
|
| 219 | pub mod __internal;
|
| 220 | #[doc(hidden)]
|
| 221 | pub mod macros;
|
| 222 |
|
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | #[macro_export]
|
| 262 | macro_rules! stack_pin_init {
|
| 263 | (let $var:ident $(: $t:ty)? = $val:expr) => {
|
| 264 | let val = $val;
|
| 265 | let mut $var = ::core::pin::pin!($crate::init::__internal::StackInit$(::<$t>)?::uninit());
|
| 266 | let mut $var = match $crate::init::__internal::StackInit::init($var, val) {
|
| 267 | Ok(res) => res,
|
| 268 | Err(x) => {
|
| 269 | let x: ::core::convert::Infallible = x;
|
| 270 | match x {}
|
| 271 | }
|
| 272 | };
|
| 273 | };
|
| 274 | }
|
| 275 |
|
| 276 | /// Initialize and pin a type directly on the stack.
|
| 277 | ///
|
| 278 | /// # Examples
|
| 279 | ///
|
| 280 | /// ```rust
|
| 281 | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)]
|
| 282 | /// # use kernel::{init, pin_init, stack_try_pin_init, init::*, sync::Mutex, new_mutex};
|
| 283 | /// # use macros::pin_data;
|
| 284 | /// # use core::{alloc::AllocError, pin::Pin};
|
| 285 | /// #[pin_data]
|
| 286 | /// struct Foo {
|
| 287 | /// #[pin]
|
| 288 | /// a: Mutex<usize>,
|
| 289 | /// b: Box<Bar>,
|
| 290 | /// }
|
| 291 | ///
|
| 292 | /// struct Bar {
|
| 293 | /// x: u32,
|
| 294 | /// }
|
| 295 | ///
|
| 296 | /// stack_try_pin_init!(let foo: Result<Pin<&mut Foo>, AllocError> = pin_init!(Foo {
|
| 297 | /// a <- new_mutex!(42),
|
| 298 | /// b: Box::try_new(Bar {
|
| 299 | /// x: 64,
|
| 300 | /// })?,
|
| 301 | /// }));
|
| 302 | /// let foo = foo.unwrap();
|
| 303 | /// pr_info!("a: {}", &*foo.a.lock());
|
| 304 | /// ```
|
| 305 | ///
|
| 306 | /// ```rust
|
| 307 | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)]
|
| 308 | /// # use kernel::{init, pin_init, stack_try_pin_init, init::*, sync::Mutex, new_mutex};
|
| 309 | /// # use macros::pin_data;
|
| 310 | /// # use core::{alloc::AllocError, pin::Pin};
|
| 311 | /// #[pin_data]
|
| 312 | /// struct Foo {
|
| 313 | /// #[pin]
|
| 314 | /// a: Mutex<usize>,
|
| 315 | /// b: Box<Bar>,
|
| 316 | /// }
|
| 317 | ///
|
| 318 | /// struct Bar {
|
| 319 | /// x: u32,
|
| 320 | /// }
|
| 321 | ///
|
| 322 | /// stack_try_pin_init!(let foo: Pin<&mut Foo> =? pin_init!(Foo {
|
| 323 | /// a <- new_mutex!(42),
|
| 324 | /// b: Box::try_new(Bar {
|
| 325 | /// x: 64,
|
| 326 | /// })?,
|
| 327 | /// }));
|
| 328 | /// pr_info!("a: {}", &*foo.a.lock());
|
| 329 | /// # Ok::<_, AllocError>(())
|
| 330 | /// ```
|
| 331 | ///
|
| 332 | /// # Syntax
|
| 333 | ///
|
| 334 | /// A normal `let` binding with optional type annotation. The expression is expected to implement
|
| 335 | /// [`PinInit`]/[`Init`]. This macro assigns a result to the given variable, adding a `?` after the
|
| 336 | /// `=` will propagate this error.
|
| 337 | #[macro_export]
|
| 338 | macro_rules! stack_try_pin_init {
|
| 339 | (let $var:ident $(: $t:ty)? = $val:expr) => {
|
| 340 | let val = $val;
|
| 341 | let mut $var = ::core::pin::pin!($crate::init::__internal::StackInit$(::<$t>)?::uninit());
|
| 342 | let mut $var = $crate::init::__internal::StackInit::init($var, val);
|
| 343 | };
|
| 344 | (let $var:ident $(: $t:ty)? =? $val:expr) => {
|
| 345 | let val = $val;
|
| 346 | let mut $var = ::core::pin::pin!($crate::init::__internal::StackInit$(::<$t>)?::uninit());
|
| 347 | let mut $var = $crate::init::__internal::StackInit::init($var, val)?;
|
| 348 | };
|
| 349 | }
|
| 350 |
|
| 351 | /// Construct an in-place, pinned initializer for `struct`s.
|
| 352 | ///
|
| 353 | /// This macro defaults the error to [`Infallible`]. If you need [`Error`], then use
|
| 354 | /// [`try_pin_init!`].
|
| 355 | ///
|
| 356 | /// The syntax is almost identical to that of a normal `struct` initializer:
|
| 357 | ///
|
| 358 | /// ```rust
|
| 359 | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)]
|
| 360 | /// # use kernel::{init, pin_init, macros::pin_data, init::*};
|
| 361 | /// # use core::pin::Pin;
|
| 362 | /// #[pin_data]
|
| 363 | /// struct Foo {
|
| 364 | /// a: usize,
|
| 365 | /// b: Bar,
|
| 366 | /// }
|
| 367 | ///
|
| 368 | /// #[pin_data]
|
| 369 | /// struct Bar {
|
| 370 | /// x: u32,
|
| 371 | /// }
|
| 372 | ///
|
| 373 | /// # fn demo() -> impl PinInit<Foo> {
|
| 374 | /// let a = 42;
|
| 375 | ///
|
| 376 | /// let initializer = pin_init!(Foo {
|
| 377 | /// a,
|
| 378 | /// b: Bar {
|
| 379 | /// x: 64,
|
| 380 | /// },
|
| 381 | /// });
|
| 382 | /// # initializer }
|
| 383 | /// # Box::pin_init(demo()).unwrap();
|
| 384 | /// ```
|
| 385 | ///
|
| 386 | /// Arbitrary Rust expressions can be used to set the value of a variable.
|
| 387 | ///
|
| 388 | /// The fields are initialized in the order that they appear in the initializer. So it is possible
|
| 389 | /// to read already initialized fields using raw pointers.
|
| 390 | ///
|
| 391 | /// IMPORTANT: You are not allowed to create references to fields of the struct inside of the
|
| 392 | /// initializer.
|
| 393 | ///
|
| 394 | /// # Init-functions
|
| 395 | ///
|
| 396 | /// When working with this API it is often desired to let others construct your types without
|
| 397 | /// giving access to all fields. This is where you would normally write a plain function `new`
|
| 398 | /// that would return a new instance of your type. With this API that is also possible.
|
| 399 | /// However, there are a few extra things to keep in mind.
|
| 400 | ///
|
| 401 | /// To create an initializer function, simply declare it like this:
|
| 402 | ///
|
| 403 | /// ```rust
|
| 404 | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)]
|
| 405 | /// # use kernel::{init, pin_init, prelude::*, init::*};
|
| 406 | /// # use core::pin::Pin;
|
| 407 | /// # #[pin_data]
|
| 408 | /// # struct Foo {
|
| 409 | /// # a: usize,
|
| 410 | /// # b: Bar,
|
| 411 | /// # }
|
| 412 | /// # #[pin_data]
|
| 413 | /// # struct Bar {
|
| 414 | /// # x: u32,
|
| 415 | /// # }
|
| 416 | /// impl Foo {
|
| 417 | /// fn new() -> impl PinInit<Self> {
|
| 418 | /// pin_init!(Self {
|
| 419 | /// a: 42,
|
| 420 | /// b: Bar {
|
| 421 | /// x: 64,
|
| 422 | /// },
|
| 423 | /// })
|
| 424 | /// }
|
| 425 | /// }
|
| 426 | /// ```
|
| 427 | ///
|
| 428 | /// Users of `Foo` can now create it like this:
|
| 429 | ///
|
| 430 | /// ```rust
|
| 431 | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)]
|
| 432 | /// # use kernel::{init, pin_init, macros::pin_data, init::*};
|
| 433 | /// # use core::pin::Pin;
|
| 434 | /// # #[pin_data]
|
| 435 | /// # struct Foo {
|
| 436 | /// # a: usize,
|
| 437 | /// # b: Bar,
|
| 438 | /// # }
|
| 439 | /// # #[pin_data]
|
| 440 | /// # struct Bar {
|
| 441 | /// # x: u32,
|
| 442 | /// # }
|
| 443 | /// # impl Foo {
|
| 444 | /// # fn new() -> impl PinInit<Self> {
|
| 445 | /// # pin_init!(Self {
|
| 446 | /// # a: 42,
|
| 447 | /// # b: Bar {
|
| 448 | /// # x: 64,
|
| 449 | /// # },
|
| 450 | /// # })
|
| 451 | /// # }
|
| 452 | /// # }
|
| 453 | /// let foo = Box::pin_init(Foo::new());
|
| 454 | /// ```
|
| 455 | ///
|
| 456 | /// They can also easily embed it into their own `struct`s:
|
| 457 | ///
|
| 458 | /// ```rust
|
| 459 | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)]
|
| 460 | /// # use kernel::{init, pin_init, macros::pin_data, init::*};
|
| 461 | /// # use core::pin::Pin;
|
| 462 | /// # #[pin_data]
|
| 463 | /// # struct Foo {
|
| 464 | /// # a: usize,
|
| 465 | /// # b: Bar,
|
| 466 | /// # }
|
| 467 | /// # #[pin_data]
|
| 468 | /// # struct Bar {
|
| 469 | /// # x: u32,
|
| 470 | /// # }
|
| 471 | /// # impl Foo {
|
| 472 | /// # fn new() -> impl PinInit<Self> {
|
| 473 | /// # pin_init!(Self {
|
| 474 | /// # a: 42,
|
| 475 | /// # b: Bar {
|
| 476 | /// # x: 64,
|
| 477 | /// # },
|
| 478 | /// # })
|
| 479 | /// # }
|
| 480 | /// # }
|
| 481 | /// #[pin_data]
|
| 482 | /// struct FooContainer {
|
| 483 | /// #[pin]
|
| 484 | /// foo1: Foo,
|
| 485 | /// #[pin]
|
| 486 | /// foo2: Foo,
|
| 487 | /// other: u32,
|
| 488 | /// }
|
| 489 | ///
|
| 490 | /// impl FooContainer {
|
| 491 | /// fn new(other: u32) -> impl PinInit<Self> {
|
| 492 | /// pin_init!(Self {
|
| 493 | /// foo1 <- Foo::new(),
|
| 494 | /// foo2 <- Foo::new(),
|
| 495 | /// other,
|
| 496 | /// })
|
| 497 | /// }
|
| 498 | /// }
|
| 499 | /// ```
|
| 500 | ///
|
| 501 | /// Here we see that when using `pin_init!` with `PinInit`, one needs to write `<-` instead of `:`.
|
| 502 | /// This signifies that the given field is initialized in-place. As with `struct` initializers, just
|
| 503 | /// writing the field (in this case `other`) without `:` or `<-` means `other: other,`.
|
| 504 | ///
|
| 505 | /// # Syntax
|
| 506 | ///
|
| 507 | /// As already mentioned in the examples above, inside of `pin_init!` a `struct` initializer with
|
| 508 | /// the following modifications is expected:
|
| 509 | /// - Fields that you want to initialize in-place have to use `<-` instead of `:`.
|
| 510 | /// - In front of the initializer you can write `&this in` to have access to a [`NonNull<Self>`]
|
| 511 | /// pointer named `this` inside of the initializer.
|
| 512 | ///
|
| 513 | /// For instance:
|
| 514 | ///
|
| 515 | /// ```rust
|
| 516 | /// # use kernel::pin_init;
|
| 517 | /// # use macros::pin_data;
|
| 518 | /// # use core::{ptr::addr_of_mut, marker::PhantomPinned};
|
| 519 | /// #[pin_data]
|
| 520 | /// struct Buf {
|
| 521 | /// // `ptr` points into `buf`.
|
| 522 | /// ptr: *mut u8,
|
| 523 | /// buf: [u8; 64],
|
| 524 | /// #[pin]
|
| 525 | /// pin: PhantomPinned,
|
| 526 | /// }
|
| 527 | /// pin_init!(&this in Buf {
|
| 528 | /// buf: [0; 64],
|
| 529 | /// ptr: unsafe { addr_of_mut!((*this.as_ptr()).buf).cast() },
|
| 530 | /// pin: PhantomPinned,
|
| 531 | /// });
|
| 532 | /// ```
|
| 533 | ///
|
| 534 | /// [`try_pin_init!`]: kernel::try_pin_init
|
| 535 | /// [`NonNull<Self>`]: core::ptr::NonNull
|
| 536 | // For a detailed example of how this macro works, see the module documentation of the hidden
|
| 537 | // module `__internal` inside of `init/__internal.rs`.
|
| 538 | #[macro_export]
|
| 539 | macro_rules! pin_init {
|
| 540 | ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
|
| 541 | $($fields:tt)*
|
| 542 | }) => {
|
| 543 | $crate::try_pin_init!(
|
| 544 | @this($($this)?),
|
| 545 | @typ($t $(::<$($generics),*>)?),
|
| 546 | @fields($($fields)*),
|
| 547 | @error(::core::convert::Infallible),
|
| 548 | )
|
| 549 | };
|
| 550 | }
|
| 551 |
|
| 552 | |
| 553 | |
| 554 | |
| 555 | |
| 556 | |
| 557 | |
| 558 | |
| 559 | |
| 560 | |
| 561 | |
| 562 | |
| 563 | |
| 564 | |
| 565 | |
| 566 | |
| 567 | |
| 568 | |
| 569 | |
| 570 | |
| 571 | |
| 572 | |
| 573 | |
| 574 | |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | |
| 580 | |
| 581 | |
| 582 | |
| 583 | |
| 584 | |
| 585 | |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | |
| 591 | #[macro_export]
|
| 592 | macro_rules! try_pin_init {
|
| 593 | ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
|
| 594 | $($fields:tt)*
|
| 595 | }) => {
|
| 596 | $crate::try_pin_init!(
|
| 597 | @this($($this)?),
|
| 598 | @typ($t $(::<$($generics),*>)? ),
|
| 599 | @fields($($fields)*),
|
| 600 | @error($crate::error::Error),
|
| 601 | )
|
| 602 | };
|
| 603 | ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
|
| 604 | $($fields:tt)*
|
| 605 | }? $err:ty) => {
|
| 606 | $crate::try_pin_init!(
|
| 607 | @this($($this)?),
|
| 608 | @typ($t $(::<$($generics),*>)? ),
|
| 609 | @fields($($fields)*),
|
| 610 | @error($err),
|
| 611 | )
|
| 612 | };
|
| 613 | (
|
| 614 | @this($($this:ident)?),
|
| 615 | @typ($t:ident $(::<$($generics:ty),*>)?),
|
| 616 | @fields($($fields:tt)*),
|
| 617 | @error($err:ty),
|
| 618 | ) => {{
|
| 619 | |
| 620 | |
| 621 | |
| 622 | struct __InitOk;
|
| 623 | |
| 624 | let data = unsafe {
|
| 625 | use $crate::init::__internal::HasPinData;
|
| 626 | $t$(::<$($generics),*>)?::__pin_data()
|
| 627 | };
|
| 628 | |
| 629 | let init = $crate::init::__internal::PinData::make_closure::<_, __InitOk, $err>(
|
| 630 | data,
|
| 631 | move |slot| {
|
| 632 | {
|
| 633 | |
| 634 | struct __InitOk;
|
| 635 | |
| 636 | |
| 637 | $(let $this = unsafe { ::core::ptr::NonNull::new_unchecked(slot) };)?
|
| 638 | |
| 639 | $crate::try_pin_init!(init_slot:
|
| 640 | @data(data),
|
| 641 | @slot(slot),
|
| 642 | @munch_fields($($fields)*,),
|
| 643 | );
|
| 644 | |
| 645 | |
| 646 | |
| 647 | #[allow(unreachable_code, clippy::diverging_sub_expression)]
|
| 648 | if false {
|
| 649 | $crate::try_pin_init!(make_initializer:
|
| 650 | @slot(slot),
|
| 651 | @type_name($t),
|
| 652 | @munch_fields($($fields)*,),
|
| 653 | @acc(),
|
| 654 | );
|
| 655 | }
|
| 656 | |
| 657 | $crate::try_pin_init!(forget_guards:
|
| 658 | @munch_fields($($fields)*,),
|
| 659 | );
|
| 660 | }
|
| 661 | Ok(__InitOk)
|
| 662 | }
|
| 663 | );
|
| 664 | let init = move |slot| -> ::core::result::Result<(), $err> {
|
| 665 | init(slot).map(|__InitOk| ())
|
| 666 | };
|
| 667 | let init = unsafe { $crate::init::pin_init_from_closure::<_, $err>(init) };
|
| 668 | init
|
| 669 | }};
|
| 670 | (init_slot:
|
| 671 | @data($data:ident),
|
| 672 | @slot($slot:ident),
|
| 673 | @munch_fields($(,)?),
|
| 674 | ) => {
|
| 675 | // Endpoint of munching, no fields are left.
|
| 676 | };
|
| 677 | (init_slot:
|
| 678 | @data($data:ident),
|
| 679 | @slot($slot:ident),
|
| 680 | // In-place initialization syntax.
|
| 681 | @munch_fields($field:ident <- $val:expr, $($rest:tt)*),
|
| 682 | ) => {
|
| 683 | let $field = $val;
|
| 684 | |
| 685 | |
| 686 | |
| 687 | |
| 688 | |
| 689 | unsafe { $data.$field(::core::ptr::addr_of_mut!((*$slot).$field), $field)? };
|
| 690 | |
| 691 | |
| 692 | |
| 693 | |
| 694 | |
| 695 | let $field = &unsafe {
|
| 696 | $crate::init::__internal::DropGuard::new(::core::ptr::addr_of_mut!((*$slot).$field))
|
| 697 | };
|
| 698 |
|
| 699 | $crate::try_pin_init!(init_slot:
|
| 700 | @data($data),
|
| 701 | @slot($slot),
|
| 702 | @munch_fields($($rest)*),
|
| 703 | );
|
| 704 | };
|
| 705 | (init_slot:
|
| 706 | @data($data:ident),
|
| 707 | @slot($slot:ident),
|
| 708 | |
| 709 | @munch_fields($field:ident $(: $val:expr)?, $($rest:tt)*),
|
| 710 | ) => {
|
| 711 | $(let $field = $val;)?
|
| 712 | |
| 713 | |
| 714 | |
| 715 | unsafe { ::core::ptr::write(::core::ptr::addr_of_mut!((*$slot).$field), $field) };
|
| 716 | |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | let $field = &unsafe {
|
| 722 | $crate::init::__internal::DropGuard::new(::core::ptr::addr_of_mut!((*$slot).$field))
|
| 723 | };
|
| 724 |
|
| 725 | $crate::try_pin_init!(init_slot:
|
| 726 | @data($data),
|
| 727 | @slot($slot),
|
| 728 | @munch_fields($($rest)*),
|
| 729 | );
|
| 730 | };
|
| 731 | (make_initializer:
|
| 732 | @slot($slot:ident),
|
| 733 | @type_name($t:ident),
|
| 734 | @munch_fields($(,)?),
|
| 735 | @acc($($acc:tt)*),
|
| 736 | ) => {
|
| 737 | |
| 738 | |
| 739 | |
| 740 | unsafe {
|
| 741 | ::core::ptr::write($slot, $t {
|
| 742 | $($acc)*
|
| 743 | });
|
| 744 | }
|
| 745 | };
|
| 746 | (make_initializer:
|
| 747 | @slot($slot:ident),
|
| 748 | @type_name($t:ident),
|
| 749 | @munch_fields($field:ident <- $val:expr, $($rest:tt)*),
|
| 750 | @acc($($acc:tt)*),
|
| 751 | ) => {
|
| 752 | $crate::try_pin_init!(make_initializer:
|
| 753 | @slot($slot),
|
| 754 | @type_name($t),
|
| 755 | @munch_fields($($rest)*),
|
| 756 | @acc($($acc)* $field: ::core::panic!(),),
|
| 757 | );
|
| 758 | };
|
| 759 | (make_initializer:
|
| 760 | @slot($slot:ident),
|
| 761 | @type_name($t:ident),
|
| 762 | @munch_fields($field:ident $(: $val:expr)?, $($rest:tt)*),
|
| 763 | @acc($($acc:tt)*),
|
| 764 | ) => {
|
| 765 | $crate::try_pin_init!(make_initializer:
|
| 766 | @slot($slot),
|
| 767 | @type_name($t),
|
| 768 | @munch_fields($($rest)*),
|
| 769 | @acc($($acc)* $field: ::core::panic!(),),
|
| 770 | );
|
| 771 | };
|
| 772 | (forget_guards:
|
| 773 | @munch_fields($(,)?),
|
| 774 | ) => {
|
| 775 | |
| 776 | };
|
| 777 | (forget_guards:
|
| 778 | @munch_fields($field:ident <- $val:expr, $($rest:tt)*),
|
| 779 | ) => {
|
| 780 | unsafe { $crate::init::__internal::DropGuard::forget($field) };
|
| 781 |
|
| 782 | $crate::try_pin_init!(forget_guards:
|
| 783 | @munch_fields($($rest)*),
|
| 784 | );
|
| 785 | };
|
| 786 | (forget_guards:
|
| 787 | @munch_fields($field:ident $(: $val:expr)?, $($rest:tt)*),
|
| 788 | ) => {
|
| 789 | unsafe { $crate::init::__internal::DropGuard::forget($field) };
|
| 790 |
|
| 791 | $crate::try_pin_init!(forget_guards:
|
| 792 | @munch_fields($($rest)*),
|
| 793 | );
|
| 794 | };
|
| 795 | }
|
| 796 |
|
| 797 | |
| 798 | |
| 799 | |
| 800 | |
| 801 | |
| 802 | |
| 803 | |
| 804 | |
| 805 | |
| 806 | |
| 807 | |
| 808 | |
| 809 | |
| 810 | |
| 811 | |
| 812 | |
| 813 | |
| 814 | #[macro_export]
|
| 815 | macro_rules! init {
|
| 816 | ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
|
| 817 | $($fields:tt)*
|
| 818 | }) => {
|
| 819 | $crate::try_init!(
|
| 820 | @this($($this)?),
|
| 821 | @typ($t $(::<$($generics),*>)?),
|
| 822 | @fields($($fields)*),
|
| 823 | @error(::core::convert::Infallible),
|
| 824 | )
|
| 825 | }
|
| 826 | }
|
| 827 |
|
| 828 | |
| 829 | |
| 830 | |
| 831 | |
| 832 | |
| 833 | |
| 834 | |
| 835 | |
| 836 | |
| 837 | |
| 838 | |
| 839 | |
| 840 | |
| 841 | |
| 842 | |
| 843 | |
| 844 | |
| 845 | |
| 846 | |
| 847 | |
| 848 | |
| 849 | |
| 850 | |
| 851 | |
| 852 | |
| 853 | |
| 854 | |
| 855 | |
| 856 | |
| 857 | |
| 858 | |
| 859 | |
| 860 | |
| 861 | #[macro_export]
|
| 862 | macro_rules! try_init {
|
| 863 | ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
|
| 864 | $($fields:tt)*
|
| 865 | }) => {
|
| 866 | $crate::try_init!(
|
| 867 | @this($($this)?),
|
| 868 | @typ($t $(::<$($generics),*>)?),
|
| 869 | @fields($($fields)*),
|
| 870 | @error($crate::error::Error),
|
| 871 | )
|
| 872 | };
|
| 873 | ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
|
| 874 | $($fields:tt)*
|
| 875 | }? $err:ty) => {
|
| 876 | $crate::try_init!(
|
| 877 | @this($($this)?),
|
| 878 | @typ($t $(::<$($generics),*>)?),
|
| 879 | @fields($($fields)*),
|
| 880 | @error($err),
|
| 881 | )
|
| 882 | };
|
| 883 | (
|
| 884 | @this($($this:ident)?),
|
| 885 | @typ($t:ident $(::<$($generics:ty),*>)?),
|
| 886 | @fields($($fields:tt)*),
|
| 887 | @error($err:ty),
|
| 888 | ) => {{
|
| 889 | |
| 890 | |
| 891 | |
| 892 | struct __InitOk;
|
| 893 | |
| 894 | let data = unsafe {
|
| 895 | use $crate::init::__internal::HasInitData;
|
| 896 | $t$(::<$($generics),*>)?::__init_data()
|
| 897 | };
|
| 898 | |
| 899 | let init = $crate::init::__internal::InitData::make_closure::<_, __InitOk, $err>(
|
| 900 | data,
|
| 901 | move |slot| {
|
| 902 | {
|
| 903 | |
| 904 | struct __InitOk;
|
| 905 | |
| 906 | |
| 907 | $(let $this = unsafe { ::core::ptr::NonNull::new_unchecked(slot) };)?
|
| 908 | |
| 909 | $crate::try_init!(init_slot:
|
| 910 | @slot(slot),
|
| 911 | @munch_fields($($fields)*,),
|
| 912 | );
|
| 913 | |
| 914 | |
| 915 | |
| 916 | #[allow(unreachable_code, clippy::diverging_sub_expression)]
|
| 917 | if false {
|
| 918 | $crate::try_init!(make_initializer:
|
| 919 | @slot(slot),
|
| 920 | @type_name($t),
|
| 921 | @munch_fields($($fields)*,),
|
| 922 | @acc(),
|
| 923 | );
|
| 924 | }
|
| 925 | |
| 926 | $crate::try_init!(forget_guards:
|
| 927 | @munch_fields($($fields)*,),
|
| 928 | );
|
| 929 | }
|
| 930 | Ok(__InitOk)
|
| 931 | }
|
| 932 | );
|
| 933 | let init = move |slot| -> ::core::result::Result<(), $err> {
|
| 934 | init(slot).map(|__InitOk| ())
|
| 935 | };
|
| 936 | let init = unsafe { $crate::init::init_from_closure::<_, $err>(init) };
|
| 937 | init
|
| 938 | }};
|
| 939 | (init_slot:
|
| 940 | @slot($slot:ident),
|
| 941 | @munch_fields( $(,)?),
|
| 942 | ) => {
|
| 943 | |
| 944 | };
|
| 945 | (init_slot:
|
| 946 | @slot($slot:ident),
|
| 947 | @munch_fields($field:ident <- $val:expr, $($rest:tt)*),
|
| 948 | ) => {
|
| 949 | let $field = $val;
|
| 950 | |
| 951 | |
| 952 | |
| 953 | |
| 954 | unsafe {
|
| 955 | $crate::init::Init::__init($field, ::core::ptr::addr_of_mut!((*$slot).$field))?;
|
| 956 | }
|
| 957 | |
| 958 | |
| 959 | |
| 960 | |
| 961 | |
| 962 | let $field = &unsafe {
|
| 963 | $crate::init::__internal::DropGuard::new(::core::ptr::addr_of_mut!((*$slot).$field))
|
| 964 | };
|
| 965 |
|
| 966 | $crate::try_init!(init_slot:
|
| 967 | @slot($slot),
|
| 968 | @munch_fields($($rest)*),
|
| 969 | );
|
| 970 | };
|
| 971 | (init_slot:
|
| 972 | @slot($slot:ident),
|
| 973 | |
| 974 | @munch_fields($field:ident $(: $val:expr)?, $($rest:tt)*),
|
| 975 | ) => {
|
| 976 | $(let $field = $val;)?
|
| 977 | |
| 978 | |
| 979 | |
| 980 | unsafe { ::core::ptr::write(::core::ptr::addr_of_mut!((*$slot).$field), $field) };
|
| 981 | |
| 982 | |
| 983 | |
| 984 | |
| 985 | |
| 986 | let $field = &unsafe {
|
| 987 | $crate::init::__internal::DropGuard::new(::core::ptr::addr_of_mut!((*$slot).$field))
|
| 988 | };
|
| 989 |
|
| 990 | $crate::try_init!(init_slot:
|
| 991 | @slot($slot),
|
| 992 | @munch_fields($($rest)*),
|
| 993 | );
|
| 994 | };
|
| 995 | (make_initializer:
|
| 996 | @slot($slot:ident),
|
| 997 | @type_name($t:ident),
|
| 998 | @munch_fields( $(,)?),
|
| 999 | @acc($($acc:tt)*),
|
| 1000 | ) => {
|
| 1001 | |
| 1002 | |
| 1003 | |
| 1004 | unsafe {
|
| 1005 | ::core::ptr::write($slot, $t {
|
| 1006 | $($acc)*
|
| 1007 | });
|
| 1008 | }
|
| 1009 | };
|
| 1010 | (make_initializer:
|
| 1011 | @slot($slot:ident),
|
| 1012 | @type_name($t:ident),
|
| 1013 | @munch_fields($field:ident <- $val:expr, $($rest:tt)*),
|
| 1014 | @acc($($acc:tt)*),
|
| 1015 | ) => {
|
| 1016 | $crate::try_init!(make_initializer:
|
| 1017 | @slot($slot),
|
| 1018 | @type_name($t),
|
| 1019 | @munch_fields($($rest)*),
|
| 1020 | @acc($($acc)*$field: ::core::panic!(),),
|
| 1021 | );
|
| 1022 | };
|
| 1023 | (make_initializer:
|
| 1024 | @slot($slot:ident),
|
| 1025 | @type_name($t:ident),
|
| 1026 | @munch_fields($field:ident $(: $val:expr)?, $($rest:tt)*),
|
| 1027 | @acc($($acc:tt)*),
|
| 1028 | ) => {
|
| 1029 | $crate::try_init!(make_initializer:
|
| 1030 | @slot($slot),
|
| 1031 | @type_name($t),
|
| 1032 | @munch_fields($($rest)*),
|
| 1033 | @acc($($acc)*$field: ::core::panic!(),),
|
| 1034 | );
|
| 1035 | };
|
| 1036 | (forget_guards:
|
| 1037 | @munch_fields($(,)?),
|
| 1038 | ) => {
|
| 1039 | |
| 1040 | };
|
| 1041 | (forget_guards:
|
| 1042 | @munch_fields($field:ident <- $val:expr, $($rest:tt)*),
|
| 1043 | ) => {
|
| 1044 | unsafe { $crate::init::__internal::DropGuard::forget($field) };
|
| 1045 |
|
| 1046 | $crate::try_init!(forget_guards:
|
| 1047 | @munch_fields($($rest)*),
|
| 1048 | );
|
| 1049 | };
|
| 1050 | (forget_guards:
|
| 1051 | @munch_fields($field:ident $(: $val:expr)?, $($rest:tt)*),
|
| 1052 | ) => {
|
| 1053 | unsafe { $crate::init::__internal::DropGuard::forget($field) };
|
| 1054 |
|
| 1055 | $crate::try_init!(forget_guards:
|
| 1056 | @munch_fields($($rest)*),
|
| 1057 | );
|
| 1058 | };
|
| 1059 | }
|
| 1060 |
|
| 1061 | |
| 1062 | |
| 1063 | |
| 1064 | |
| 1065 | |
| 1066 | |
| 1067 | |
| 1068 | |
| 1069 | |
| 1070 | |
| 1071 | |
| 1072 | |
| 1073 | |
| 1074 | |
| 1075 | |
| 1076 | |
| 1077 | |
| 1078 | |
| 1079 | |
| 1080 | |
| 1081 | |
| 1082 | |
| 1083 | |
| 1084 | #[must_use = "An initializer must be used in order to create its value."]
|
| 1085 | pub unsafe trait PinInit<T: ?Sized, E = Infallible>: Sized {
|
| 1086 | |
| 1087 | |
| 1088 | |
| 1089 | |
| 1090 | |
| 1091 | |
| 1092 | |
| 1093 | |
| 1094 | unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E>;
|
| 1095 | }
|
| 1096 |
|
| 1097 | |
| 1098 | |
| 1099 | |
| 1100 | |
| 1101 | |
| 1102 | |
| 1103 | |
| 1104 | |
| 1105 | |
| 1106 | |
| 1107 | |
| 1108 | |
| 1109 | |
| 1110 | |
| 1111 | |
| 1112 | |
| 1113 | |
| 1114 | |
| 1115 | |
| 1116 | |
| 1117 | |
| 1118 | |
| 1119 | |
| 1120 | |
| 1121 | |
| 1122 | |
| 1123 | |
| 1124 | |
| 1125 | |
| 1126 | #[must_use = "An initializer must be used in order to create its value."]
|
| 1127 | pub unsafe trait Init<T: ?Sized, E = Infallible>: Sized {
|
| 1128 | |
| 1129 | |
| 1130 | |
| 1131 | |
| 1132 | |
| 1133 | |
| 1134 | |
| 1135 | unsafe fn __init(self, slot: *mut T) -> Result<(), E>;
|
| 1136 | }
|
| 1137 |
|
| 1138 | |
| 1139 | unsafe impl<T: ?Sized, E, I> PinInit<T, E> for I
|
| 1140 | where
|
| 1141 | I: Init<T, E>,
|
| 1142 | {
|
| 1143 | unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> {
|
| 1144 | |
| 1145 | |
| 1146 | unsafe { self.__init(slot) }
|
| 1147 | }
|
| 1148 | }
|
| 1149 |
|
| 1150 | |
| 1151 | |
| 1152 | |
| 1153 | |
| 1154 | |
| 1155 | |
| 1156 | |
| 1157 | |
| 1158 | |
| 1159 | |
| 1160 | |
| 1161 | |
| 1162 | #[inline]
|
| 1163 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>(
|
| 1164 | f: impl FnOnce(*mut T) -> Result<(), E>,
|
| 1165 | ) -> impl PinInit<T, E> {
|
| 1166 | __internal::InitClosure(f, PhantomData)
|
| 1167 | }
|
| 1168 |
|
| 1169 | |
| 1170 | |
| 1171 | |
| 1172 | |
| 1173 | |
| 1174 | |
| 1175 | |
| 1176 | |
| 1177 | |
| 1178 | |
| 1179 | |
| 1180 | |
| 1181 | #[inline]
|
| 1182 | pub const unsafe fn init_from_closure<T: ?Sized, E>(
|
| 1183 | f: impl FnOnce(*mut T) -> Result<(), E>,
|
| 1184 | ) -> impl Init<T, E> {
|
| 1185 | __internal::InitClosure(f, PhantomData)
|
| 1186 | }
|
| 1187 |
|
| 1188 | |
| 1189 | |
| 1190 | |
| 1191 | #[inline]
|
| 1192 | pub fn uninit<T, E>() -> impl Init<MaybeUninit<T>, E> {
|
| 1193 | |
| 1194 | unsafe { init_from_closure(|_| Ok(())) }
|
| 1195 | }
|
| 1196 |
|
| 1197 | |
| 1198 | unsafe impl<T, E> Init<T, E> for T {
|
| 1199 | unsafe fn __init(self, slot: *mut T) -> Result<(), E> {
|
| 1200 | unsafe { slot.write(self) };
|
| 1201 | Ok(())
|
| 1202 | }
|
| 1203 | }
|
| 1204 |
|
| 1205 | |
| 1206 | pub trait InPlaceInit<T>: Sized {
|
| 1207 | |
| 1208 | |
| 1209 | |
| 1210 | |
| 1211 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E>
|
| 1212 | where
|
| 1213 | E: From<AllocError>;
|
| 1214 |
|
| 1215 | |
| 1216 | |
| 1217 | |
| 1218 | |
| 1219 | fn pin_init<E>(init: impl PinInit<T, E>) -> error::Result<Pin<Self>>
|
| 1220 | where
|
| 1221 | Error: From<E>,
|
| 1222 | {
|
| 1223 | |
| 1224 | let init = unsafe {
|
| 1225 | pin_init_from_closure(|slot| init.__pinned_init(slot).map_err(|e| Error::from(e)))
|
| 1226 | };
|
| 1227 | Self::try_pin_init(init)
|
| 1228 | }
|
| 1229 |
|
| 1230 | |
| 1231 | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E>
|
| 1232 | where
|
| 1233 | E: From<AllocError>;
|
| 1234 |
|
| 1235 | |
| 1236 | fn init<E>(init: impl Init<T, E>) -> error::Result<Self>
|
| 1237 | where
|
| 1238 | Error: From<E>,
|
| 1239 | {
|
| 1240 | |
| 1241 | let init = unsafe {
|
| 1242 | init_from_closure(|slot| init.__pinned_init(slot).map_err(|e| Error::from(e)))
|
| 1243 | };
|
| 1244 | Self::try_init(init)
|
| 1245 | }
|
| 1246 | }
|
| 1247 |
|
| 1248 | impl<T> InPlaceInit<T> for Box<T> {
|
| 1249 | #[inline]
|
| 1250 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E>
|
| 1251 | where
|
| 1252 | E: From<AllocError>,
|
| 1253 | {
|
| 1254 | let mut this = Box::try_new_uninit()?;
|
| 1255 | let slot = this.as_mut_ptr();
|
| 1256 | |
| 1257 | |
| 1258 | unsafe { init.__pinned_init(slot)? };
|
| 1259 | |
| 1260 | Ok(unsafe { this.assume_init() }.into())
|
| 1261 | }
|
| 1262 |
|
| 1263 | #[inline]
|
| 1264 | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E>
|
| 1265 | where
|
| 1266 | E: From<AllocError>,
|
| 1267 | {
|
| 1268 | let mut this = Box::try_new_uninit()?;
|
| 1269 | let slot = this.as_mut_ptr();
|
| 1270 | |
| 1271 | |
| 1272 | unsafe { init.__init(slot)? };
|
| 1273 | |
| 1274 | Ok(unsafe { this.assume_init() })
|
| 1275 | }
|
| 1276 | }
|
| 1277 |
|
| 1278 | impl<T> InPlaceInit<T> for UniqueArc<T> {
|
| 1279 | #[inline]
|
| 1280 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E>
|
| 1281 | where
|
| 1282 | E: From<AllocError>,
|
| 1283 | {
|
| 1284 | let mut this = UniqueArc::try_new_uninit()?;
|
| 1285 | let slot = this.as_mut_ptr();
|
| 1286 | |
| 1287 | |
| 1288 | unsafe { init.__pinned_init(slot)? };
|
| 1289 | |
| 1290 | Ok(unsafe { this.assume_init() }.into())
|
| 1291 | }
|
| 1292 |
|
| 1293 | #[inline]
|
| 1294 | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E>
|
| 1295 | where
|
| 1296 | E: From<AllocError>,
|
| 1297 | {
|
| 1298 | let mut this = UniqueArc::try_new_uninit()?;
|
| 1299 | let slot = this.as_mut_ptr();
|
| 1300 | |
| 1301 | |
| 1302 | unsafe { init.__init(slot)? };
|
| 1303 | |
| 1304 | Ok(unsafe { this.assume_init() })
|
| 1305 | }
|
| 1306 | }
|
| 1307 |
|
| 1308 | |
| 1309 | |
| 1310 | |
| 1311 | |
| 1312 | |
| 1313 | |
| 1314 | |
| 1315 | |
| 1316 | |
| 1317 | |
| 1318 | |
| 1319 | |
| 1320 | |
| 1321 | |
| 1322 | |
| 1323 | |
| 1324 | |
| 1325 | |
| 1326 | |
| 1327 | |
| 1328 | |
| 1329 | |
| 1330 | |
| 1331 | |
| 1332 | |
| 1333 | |
| 1334 | |
| 1335 | pub unsafe trait PinnedDrop: __internal::HasPinData {
|
| 1336 | |
| 1337 | |
| 1338 | |
| 1339 | |
| 1340 | |
| 1341 | |
| 1342 | |
| 1343 | |
| 1344 | fn drop(self: Pin<&mut Self>, only_call_from_drop: __internal::OnlyCallFromDrop);
|
| 1345 | }
|
| 1346 |
|
| 1347 | |
| 1348 | |
| 1349 | |
| 1350 | |
| 1351 | |
| 1352 | |
| 1353 | |
| 1354 | |
| 1355 | |
| 1356 | |
| 1357 | pub unsafe trait Zeroable {}
|
| 1358 |
|
| 1359 | |
| 1360 | |
| 1361 | |
| 1362 | #[inline]
|
| 1363 | pub fn zeroed<T: Zeroable>() -> impl Init<T> {
|
| 1364 | |
| 1365 | |
| 1366 | unsafe {
|
| 1367 | init_from_closure(|slot: *mut T| {
|
| 1368 | slot.write_bytes(0, 1);
|
| 1369 | Ok(())
|
| 1370 | })
|
| 1371 | }
|
| 1372 | }
|
| 1373 |
|
| 1374 | macro_rules! impl_zeroable {
|
| 1375 | ($($({$($generics:tt)*})? $t:ty, )*) => {
|
| 1376 | $(unsafe impl$($($generics)*)? Zeroable for $t {})*
|
| 1377 | };
|
| 1378 | }
|
| 1379 |
|
| 1380 | impl_zeroable! {
|
| 1381 | |
| 1382 | bool,
|
| 1383 | char,
|
| 1384 | u8, u16, u32, u64, u128, usize,
|
| 1385 | i8, i16, i32, i64, i128, isize,
|
| 1386 | f32, f64,
|
| 1387 |
|
| 1388 | |
| 1389 | {<T: ?Sized>} PhantomData<T>, core::marker::PhantomPinned, Infallible, (),
|
| 1390 |
|
| 1391 | |
| 1392 | {<T>} MaybeUninit<T>,
|
| 1393 |
|
| 1394 | |
| 1395 | Option<NonZeroU8>, Option<NonZeroU16>, Option<NonZeroU32>, Option<NonZeroU64>,
|
| 1396 | Option<NonZeroU128>, Option<NonZeroUsize>,
|
| 1397 | Option<NonZeroI8>, Option<NonZeroI16>, Option<NonZeroI32>, Option<NonZeroI64>,
|
| 1398 | Option<NonZeroI128>, Option<NonZeroIsize>,
|
| 1399 |
|
| 1400 | |
| 1401 | |
| 1402 | |
| 1403 | {<T: ?Sized>} Option<NonNull<T>>,
|
| 1404 | {<T: ?Sized>} Option<Box<T>>,
|
| 1405 |
|
| 1406 | |
| 1407 | |
| 1408 | |
| 1409 | |
| 1410 | |
| 1411 | |
| 1412 | |
| 1413 | {<T>} *mut T, {<T>} *const T,
|
| 1414 |
|
| 1415 | |
| 1416 | |
| 1417 | {<T>} *mut [T], {<T>} *const [T], *mut str, *const str,
|
| 1418 |
|
| 1419 | |
| 1420 | {<const N: usize, T: Zeroable>} [T; N], {<T: Zeroable>} Wrapping<T>,
|
| 1421 | }
|
| 1422 |
|
| 1423 | macro_rules! impl_tuple_zeroable {
|
| 1424 | ($(,)?) => {};
|
| 1425 | ($first:ident, $($t:ident),* $(,)?) => {
|
| 1426 | // SAFETY: All elements are zeroable and padding can be zero.
|
| 1427 | unsafe impl<$first: Zeroable, $($t: Zeroable),*> Zeroable for ($first, $($t),*) {}
|
| 1428 | impl_tuple_zeroable!($($t),* ,);
|
| 1429 | }
|
| 1430 | }
|
| 1431 |
|
| 1432 | impl_tuple_zeroable!(A, B, C, D, E, F, G, H, I, J);
|