| 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 | use crate::{
|
| 202 | error::{self, Error},
|
| 203 | sync::UniqueArc,
|
| 204 | };
|
| 205 | use alloc::boxed::Box;
|
| 206 | use core::{
|
| 207 | alloc::AllocError,
|
| 208 | cell::Cell,
|
| 209 | convert::Infallible,
|
| 210 | marker::PhantomData,
|
| 211 | mem::MaybeUninit,
|
| 212 | num::*,
|
| 213 | pin::Pin,
|
| 214 | ptr::{self, NonNull},
|
| 215 | };
|
| 216 |
|
| 217 | #[doc(hidden)]
|
| 218 | pub mod __internal;
|
| 219 | #[doc(hidden)]
|
| 220 | pub mod macros;
|
| 221 |
|
| 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 | #[macro_export]
|
| 259 | macro_rules! stack_pin_init {
|
| 260 | (let $var:ident $(: $t:ty)? = $val:expr) => {
|
| 261 | let val = $val;
|
| 262 | let mut $var = ::core::pin::pin!($crate::init::__internal::StackInit$(::<$t>)?::uninit());
|
| 263 | let mut $var = match $crate::init::__internal::StackInit::init($var, val) {
|
| 264 | Ok(res) => res,
|
| 265 | Err(x) => {
|
| 266 | let x: ::core::convert::Infallible = x;
|
| 267 | match x {}
|
| 268 | }
|
| 269 | };
|
| 270 | };
|
| 271 | }
|
| 272 |
|
| 273 | /// Initialize and pin a type directly on the stack.
|
| 274 | ///
|
| 275 | /// # Examples
|
| 276 | ///
|
| 277 | /// ```rust
|
| 278 | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)]
|
| 279 | /// # use kernel::{init, pin_init, stack_try_pin_init, init::*, sync::Mutex, new_mutex};
|
| 280 | /// # use macros::pin_data;
|
| 281 | /// # use core::{alloc::AllocError, pin::Pin};
|
| 282 | /// #[pin_data]
|
| 283 | /// struct Foo {
|
| 284 | /// #[pin]
|
| 285 | /// a: Mutex<usize>,
|
| 286 | /// b: Box<Bar>,
|
| 287 | /// }
|
| 288 | ///
|
| 289 | /// struct Bar {
|
| 290 | /// x: u32,
|
| 291 | /// }
|
| 292 | ///
|
| 293 | /// stack_try_pin_init!(let foo: Result<Pin<&mut Foo>, AllocError> = pin_init!(Foo {
|
| 294 | /// a <- new_mutex!(42),
|
| 295 | /// b: Box::try_new(Bar {
|
| 296 | /// x: 64,
|
| 297 | /// })?,
|
| 298 | /// }));
|
| 299 | /// let foo = foo.unwrap();
|
| 300 | /// pr_info!("a: {}", &*foo.a.lock());
|
| 301 | /// ```
|
| 302 | ///
|
| 303 | /// ```rust
|
| 304 | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)]
|
| 305 | /// # use kernel::{init, pin_init, stack_try_pin_init, init::*, sync::Mutex, new_mutex};
|
| 306 | /// # use macros::pin_data;
|
| 307 | /// # use core::{alloc::AllocError, pin::Pin};
|
| 308 | /// #[pin_data]
|
| 309 | /// struct Foo {
|
| 310 | /// #[pin]
|
| 311 | /// a: Mutex<usize>,
|
| 312 | /// b: Box<Bar>,
|
| 313 | /// }
|
| 314 | ///
|
| 315 | /// struct Bar {
|
| 316 | /// x: u32,
|
| 317 | /// }
|
| 318 | ///
|
| 319 | /// stack_try_pin_init!(let foo: Pin<&mut Foo> =? pin_init!(Foo {
|
| 320 | /// a <- new_mutex!(42),
|
| 321 | /// b: Box::try_new(Bar {
|
| 322 | /// x: 64,
|
| 323 | /// })?,
|
| 324 | /// }));
|
| 325 | /// pr_info!("a: {}", &*foo.a.lock());
|
| 326 | /// # Ok::<_, AllocError>(())
|
| 327 | /// ```
|
| 328 | ///
|
| 329 | /// # Syntax
|
| 330 | ///
|
| 331 | /// A normal `let` binding with optional type annotation. The expression is expected to implement
|
| 332 | /// [`PinInit`]/[`Init`]. This macro assigns a result to the given variable, adding a `?` after the
|
| 333 | /// `=` will propagate this error.
|
| 334 | #[macro_export]
|
| 335 | macro_rules! stack_try_pin_init {
|
| 336 | (let $var:ident $(: $t:ty)? = $val:expr) => {
|
| 337 | let val = $val;
|
| 338 | let mut $var = ::core::pin::pin!($crate::init::__internal::StackInit$(::<$t>)?::uninit());
|
| 339 | let mut $var = $crate::init::__internal::StackInit::init($var, val);
|
| 340 | };
|
| 341 | (let $var:ident $(: $t:ty)? =? $val:expr) => {
|
| 342 | let val = $val;
|
| 343 | let mut $var = ::core::pin::pin!($crate::init::__internal::StackInit$(::<$t>)?::uninit());
|
| 344 | let mut $var = $crate::init::__internal::StackInit::init($var, val)?;
|
| 345 | };
|
| 346 | }
|
| 347 |
|
| 348 | /// Construct an in-place, pinned initializer for `struct`s.
|
| 349 | ///
|
| 350 | /// This macro defaults the error to [`Infallible`]. If you need [`Error`], then use
|
| 351 | /// [`try_pin_init!`].
|
| 352 | ///
|
| 353 | /// The syntax is almost identical to that of a normal `struct` initializer:
|
| 354 | ///
|
| 355 | /// ```rust
|
| 356 | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)]
|
| 357 | /// # use kernel::{init, pin_init, macros::pin_data, init::*};
|
| 358 | /// # use core::pin::Pin;
|
| 359 | /// #[pin_data]
|
| 360 | /// struct Foo {
|
| 361 | /// a: usize,
|
| 362 | /// b: Bar,
|
| 363 | /// }
|
| 364 | ///
|
| 365 | /// #[pin_data]
|
| 366 | /// struct Bar {
|
| 367 | /// x: u32,
|
| 368 | /// }
|
| 369 | ///
|
| 370 | /// # fn demo() -> impl PinInit<Foo> {
|
| 371 | /// let a = 42;
|
| 372 | ///
|
| 373 | /// let initializer = pin_init!(Foo {
|
| 374 | /// a,
|
| 375 | /// b: Bar {
|
| 376 | /// x: 64,
|
| 377 | /// },
|
| 378 | /// });
|
| 379 | /// # initializer }
|
| 380 | /// # Box::pin_init(demo()).unwrap();
|
| 381 | /// ```
|
| 382 | ///
|
| 383 | /// Arbitrary Rust expressions can be used to set the value of a variable.
|
| 384 | ///
|
| 385 | /// The fields are initialized in the order that they appear in the initializer. So it is possible
|
| 386 | /// to read already initialized fields using raw pointers.
|
| 387 | ///
|
| 388 | /// IMPORTANT: You are not allowed to create references to fields of the struct inside of the
|
| 389 | /// initializer.
|
| 390 | ///
|
| 391 | /// # Init-functions
|
| 392 | ///
|
| 393 | /// When working with this API it is often desired to let others construct your types without
|
| 394 | /// giving access to all fields. This is where you would normally write a plain function `new`
|
| 395 | /// that would return a new instance of your type. With this API that is also possible.
|
| 396 | /// However, there are a few extra things to keep in mind.
|
| 397 | ///
|
| 398 | /// To create an initializer function, simply declare it like this:
|
| 399 | ///
|
| 400 | /// ```rust
|
| 401 | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)]
|
| 402 | /// # use kernel::{init, pin_init, prelude::*, init::*};
|
| 403 | /// # use core::pin::Pin;
|
| 404 | /// # #[pin_data]
|
| 405 | /// # struct Foo {
|
| 406 | /// # a: usize,
|
| 407 | /// # b: Bar,
|
| 408 | /// # }
|
| 409 | /// # #[pin_data]
|
| 410 | /// # struct Bar {
|
| 411 | /// # x: u32,
|
| 412 | /// # }
|
| 413 | /// impl Foo {
|
| 414 | /// fn new() -> impl PinInit<Self> {
|
| 415 | /// pin_init!(Self {
|
| 416 | /// a: 42,
|
| 417 | /// b: Bar {
|
| 418 | /// x: 64,
|
| 419 | /// },
|
| 420 | /// })
|
| 421 | /// }
|
| 422 | /// }
|
| 423 | /// ```
|
| 424 | ///
|
| 425 | /// Users of `Foo` can now create it like this:
|
| 426 | ///
|
| 427 | /// ```rust
|
| 428 | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)]
|
| 429 | /// # use kernel::{init, pin_init, macros::pin_data, init::*};
|
| 430 | /// # use core::pin::Pin;
|
| 431 | /// # #[pin_data]
|
| 432 | /// # struct Foo {
|
| 433 | /// # a: usize,
|
| 434 | /// # b: Bar,
|
| 435 | /// # }
|
| 436 | /// # #[pin_data]
|
| 437 | /// # struct Bar {
|
| 438 | /// # x: u32,
|
| 439 | /// # }
|
| 440 | /// # impl Foo {
|
| 441 | /// # fn new() -> impl PinInit<Self> {
|
| 442 | /// # pin_init!(Self {
|
| 443 | /// # a: 42,
|
| 444 | /// # b: Bar {
|
| 445 | /// # x: 64,
|
| 446 | /// # },
|
| 447 | /// # })
|
| 448 | /// # }
|
| 449 | /// # }
|
| 450 | /// let foo = Box::pin_init(Foo::new());
|
| 451 | /// ```
|
| 452 | ///
|
| 453 | /// They can also easily embed it into their own `struct`s:
|
| 454 | ///
|
| 455 | /// ```rust
|
| 456 | /// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)]
|
| 457 | /// # use kernel::{init, pin_init, macros::pin_data, init::*};
|
| 458 | /// # use core::pin::Pin;
|
| 459 | /// # #[pin_data]
|
| 460 | /// # struct Foo {
|
| 461 | /// # a: usize,
|
| 462 | /// # b: Bar,
|
| 463 | /// # }
|
| 464 | /// # #[pin_data]
|
| 465 | /// # struct Bar {
|
| 466 | /// # x: u32,
|
| 467 | /// # }
|
| 468 | /// # impl Foo {
|
| 469 | /// # fn new() -> impl PinInit<Self> {
|
| 470 | /// # pin_init!(Self {
|
| 471 | /// # a: 42,
|
| 472 | /// # b: Bar {
|
| 473 | /// # x: 64,
|
| 474 | /// # },
|
| 475 | /// # })
|
| 476 | /// # }
|
| 477 | /// # }
|
| 478 | /// #[pin_data]
|
| 479 | /// struct FooContainer {
|
| 480 | /// #[pin]
|
| 481 | /// foo1: Foo,
|
| 482 | /// #[pin]
|
| 483 | /// foo2: Foo,
|
| 484 | /// other: u32,
|
| 485 | /// }
|
| 486 | ///
|
| 487 | /// impl FooContainer {
|
| 488 | /// fn new(other: u32) -> impl PinInit<Self> {
|
| 489 | /// pin_init!(Self {
|
| 490 | /// foo1 <- Foo::new(),
|
| 491 | /// foo2 <- Foo::new(),
|
| 492 | /// other,
|
| 493 | /// })
|
| 494 | /// }
|
| 495 | /// }
|
| 496 | /// ```
|
| 497 | ///
|
| 498 | /// Here we see that when using `pin_init!` with `PinInit`, one needs to write `<-` instead of `:`.
|
| 499 | /// This signifies that the given field is initialized in-place. As with `struct` initializers, just
|
| 500 | /// writing the field (in this case `other`) without `:` or `<-` means `other: other,`.
|
| 501 | ///
|
| 502 | /// # Syntax
|
| 503 | ///
|
| 504 | /// As already mentioned in the examples above, inside of `pin_init!` a `struct` initializer with
|
| 505 | /// the following modifications is expected:
|
| 506 | /// - Fields that you want to initialize in-place have to use `<-` instead of `:`.
|
| 507 | /// - In front of the initializer you can write `&this in` to have access to a [`NonNull<Self>`]
|
| 508 | /// pointer named `this` inside of the initializer.
|
| 509 | ///
|
| 510 | /// For instance:
|
| 511 | ///
|
| 512 | /// ```rust
|
| 513 | /// # use kernel::pin_init;
|
| 514 | /// # use macros::pin_data;
|
| 515 | /// # use core::{ptr::addr_of_mut, marker::PhantomPinned};
|
| 516 | /// #[pin_data]
|
| 517 | /// struct Buf {
|
| 518 | /// // `ptr` points into `buf`.
|
| 519 | /// ptr: *mut u8,
|
| 520 | /// buf: [u8; 64],
|
| 521 | /// #[pin]
|
| 522 | /// pin: PhantomPinned,
|
| 523 | /// }
|
| 524 | /// pin_init!(&this in Buf {
|
| 525 | /// buf: [0; 64],
|
| 526 | /// ptr: unsafe { addr_of_mut!((*this.as_ptr()).buf).cast() },
|
| 527 | /// pin: PhantomPinned,
|
| 528 | /// });
|
| 529 | /// ```
|
| 530 | ///
|
| 531 | /// [`try_pin_init!`]: kernel::try_pin_init
|
| 532 | /// [`NonNull<Self>`]: core::ptr::NonNull
|
| 533 | // For a detailed example of how this macro works, see the module documentation of the hidden
|
| 534 | // module `__internal` inside of `init/__internal.rs`.
|
| 535 | #[macro_export]
|
| 536 | macro_rules! pin_init {
|
| 537 | ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
|
| 538 | $($fields:tt)*
|
| 539 | }) => {
|
| 540 | $crate::try_pin_init!(
|
| 541 | @this($($this)?),
|
| 542 | @typ($t $(::<$($generics),*>)?),
|
| 543 | @fields($($fields)*),
|
| 544 | @error(::core::convert::Infallible),
|
| 545 | )
|
| 546 | };
|
| 547 | }
|
| 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 | #[macro_export]
|
| 589 | macro_rules! try_pin_init {
|
| 590 | ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
|
| 591 | $($fields:tt)*
|
| 592 | }) => {
|
| 593 | $crate::try_pin_init!(
|
| 594 | @this($($this)?),
|
| 595 | @typ($t $(::<$($generics),*>)? ),
|
| 596 | @fields($($fields)*),
|
| 597 | @error($crate::error::Error),
|
| 598 | )
|
| 599 | };
|
| 600 | ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
|
| 601 | $($fields:tt)*
|
| 602 | }? $err:ty) => {
|
| 603 | $crate::try_pin_init!(
|
| 604 | @this($($this)?),
|
| 605 | @typ($t $(::<$($generics),*>)? ),
|
| 606 | @fields($($fields)*),
|
| 607 | @error($err),
|
| 608 | )
|
| 609 | };
|
| 610 | (
|
| 611 | @this($($this:ident)?),
|
| 612 | @typ($t:ident $(::<$($generics:ty),*>)?),
|
| 613 | @fields($($fields:tt)*),
|
| 614 | @error($err:ty),
|
| 615 | ) => {{
|
| 616 | |
| 617 | |
| 618 | |
| 619 | struct __InitOk;
|
| 620 | |
| 621 | let data = unsafe {
|
| 622 | use $crate::init::__internal::HasPinData;
|
| 623 | $t$(::<$($generics),*>)?::__pin_data()
|
| 624 | };
|
| 625 | |
| 626 | let init = $crate::init::__internal::PinData::make_closure::<_, __InitOk, $err>(
|
| 627 | data,
|
| 628 | move |slot| {
|
| 629 | {
|
| 630 | |
| 631 | struct __InitOk;
|
| 632 | |
| 633 | |
| 634 | $(let $this = unsafe { ::core::ptr::NonNull::new_unchecked(slot) };)?
|
| 635 | |
| 636 | $crate::try_pin_init!(init_slot:
|
| 637 | @data(data),
|
| 638 | @slot(slot),
|
| 639 | @munch_fields($($fields)*,),
|
| 640 | );
|
| 641 | |
| 642 | |
| 643 | |
| 644 | #[allow(unreachable_code, clippy::diverging_sub_expression)]
|
| 645 | if false {
|
| 646 | $crate::try_pin_init!(make_initializer:
|
| 647 | @slot(slot),
|
| 648 | @type_name($t),
|
| 649 | @munch_fields($($fields)*,),
|
| 650 | @acc(),
|
| 651 | );
|
| 652 | }
|
| 653 | |
| 654 | $crate::try_pin_init!(forget_guards:
|
| 655 | @munch_fields($($fields)*,),
|
| 656 | );
|
| 657 | }
|
| 658 | Ok(__InitOk)
|
| 659 | }
|
| 660 | );
|
| 661 | let init = move |slot| -> ::core::result::Result<(), $err> {
|
| 662 | init(slot).map(|__InitOk| ())
|
| 663 | };
|
| 664 | let init = unsafe { $crate::init::pin_init_from_closure::<_, $err>(init) };
|
| 665 | init
|
| 666 | }};
|
| 667 | (init_slot:
|
| 668 | @data($data:ident),
|
| 669 | @slot($slot:ident),
|
| 670 | @munch_fields($(,)?),
|
| 671 | ) => {
|
| 672 | // Endpoint of munching, no fields are left.
|
| 673 | };
|
| 674 | (init_slot:
|
| 675 | @data($data:ident),
|
| 676 | @slot($slot:ident),
|
| 677 | // In-place initialization syntax.
|
| 678 | @munch_fields($field:ident <- $val:expr, $($rest:tt)*),
|
| 679 | ) => {
|
| 680 | let $field = $val;
|
| 681 | |
| 682 | |
| 683 | |
| 684 | |
| 685 | |
| 686 | unsafe { $data.$field(::core::ptr::addr_of_mut!((*$slot).$field), $field)? };
|
| 687 | |
| 688 | |
| 689 | |
| 690 | |
| 691 | |
| 692 | let $field = &unsafe {
|
| 693 | $crate::init::__internal::DropGuard::new(::core::ptr::addr_of_mut!((*$slot).$field))
|
| 694 | };
|
| 695 |
|
| 696 | $crate::try_pin_init!(init_slot:
|
| 697 | @data($data),
|
| 698 | @slot($slot),
|
| 699 | @munch_fields($($rest)*),
|
| 700 | );
|
| 701 | };
|
| 702 | (init_slot:
|
| 703 | @data($data:ident),
|
| 704 | @slot($slot:ident),
|
| 705 | |
| 706 | @munch_fields($field:ident $(: $val:expr)?, $($rest:tt)*),
|
| 707 | ) => {
|
| 708 | $(let $field = $val;)?
|
| 709 | |
| 710 | |
| 711 | |
| 712 | unsafe { ::core::ptr::write(::core::ptr::addr_of_mut!((*$slot).$field), $field) };
|
| 713 | |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | let $field = &unsafe {
|
| 719 | $crate::init::__internal::DropGuard::new(::core::ptr::addr_of_mut!((*$slot).$field))
|
| 720 | };
|
| 721 |
|
| 722 | $crate::try_pin_init!(init_slot:
|
| 723 | @data($data),
|
| 724 | @slot($slot),
|
| 725 | @munch_fields($($rest)*),
|
| 726 | );
|
| 727 | };
|
| 728 | (make_initializer:
|
| 729 | @slot($slot:ident),
|
| 730 | @type_name($t:ident),
|
| 731 | @munch_fields($(,)?),
|
| 732 | @acc($($acc:tt)*),
|
| 733 | ) => {
|
| 734 | |
| 735 | |
| 736 | |
| 737 | unsafe {
|
| 738 | ::core::ptr::write($slot, $t {
|
| 739 | $($acc)*
|
| 740 | });
|
| 741 | }
|
| 742 | };
|
| 743 | (make_initializer:
|
| 744 | @slot($slot:ident),
|
| 745 | @type_name($t:ident),
|
| 746 | @munch_fields($field:ident <- $val:expr, $($rest:tt)*),
|
| 747 | @acc($($acc:tt)*),
|
| 748 | ) => {
|
| 749 | $crate::try_pin_init!(make_initializer:
|
| 750 | @slot($slot),
|
| 751 | @type_name($t),
|
| 752 | @munch_fields($($rest)*),
|
| 753 | @acc($($acc)* $field: ::core::panic!(),),
|
| 754 | );
|
| 755 | };
|
| 756 | (make_initializer:
|
| 757 | @slot($slot:ident),
|
| 758 | @type_name($t:ident),
|
| 759 | @munch_fields($field:ident $(: $val:expr)?, $($rest:tt)*),
|
| 760 | @acc($($acc:tt)*),
|
| 761 | ) => {
|
| 762 | $crate::try_pin_init!(make_initializer:
|
| 763 | @slot($slot),
|
| 764 | @type_name($t),
|
| 765 | @munch_fields($($rest)*),
|
| 766 | @acc($($acc)* $field: ::core::panic!(),),
|
| 767 | );
|
| 768 | };
|
| 769 | (forget_guards:
|
| 770 | @munch_fields($(,)?),
|
| 771 | ) => {
|
| 772 | |
| 773 | };
|
| 774 | (forget_guards:
|
| 775 | @munch_fields($field:ident <- $val:expr, $($rest:tt)*),
|
| 776 | ) => {
|
| 777 | unsafe { $crate::init::__internal::DropGuard::forget($field) };
|
| 778 |
|
| 779 | $crate::try_pin_init!(forget_guards:
|
| 780 | @munch_fields($($rest)*),
|
| 781 | );
|
| 782 | };
|
| 783 | (forget_guards:
|
| 784 | @munch_fields($field:ident $(: $val:expr)?, $($rest:tt)*),
|
| 785 | ) => {
|
| 786 | unsafe { $crate::init::__internal::DropGuard::forget($field) };
|
| 787 |
|
| 788 | $crate::try_pin_init!(forget_guards:
|
| 789 | @munch_fields($($rest)*),
|
| 790 | );
|
| 791 | };
|
| 792 | }
|
| 793 |
|
| 794 | |
| 795 | |
| 796 | |
| 797 | |
| 798 | |
| 799 | |
| 800 | |
| 801 | |
| 802 | |
| 803 | |
| 804 | |
| 805 | |
| 806 | |
| 807 | |
| 808 | |
| 809 | #[macro_export]
|
| 810 | macro_rules! init {
|
| 811 | ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
|
| 812 | $($fields:tt)*
|
| 813 | }) => {
|
| 814 | $crate::try_init!(
|
| 815 | @this($($this)?),
|
| 816 | @typ($t $(::<$($generics),*>)?),
|
| 817 | @fields($($fields)*),
|
| 818 | @error(::core::convert::Infallible),
|
| 819 | )
|
| 820 | }
|
| 821 | }
|
| 822 |
|
| 823 | |
| 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 | #[macro_export]
|
| 857 | macro_rules! try_init {
|
| 858 | ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
|
| 859 | $($fields:tt)*
|
| 860 | }) => {
|
| 861 | $crate::try_init!(
|
| 862 | @this($($this)?),
|
| 863 | @typ($t $(::<$($generics),*>)?),
|
| 864 | @fields($($fields)*),
|
| 865 | @error($crate::error::Error),
|
| 866 | )
|
| 867 | };
|
| 868 | ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
|
| 869 | $($fields:tt)*
|
| 870 | }? $err:ty) => {
|
| 871 | $crate::try_init!(
|
| 872 | @this($($this)?),
|
| 873 | @typ($t $(::<$($generics),*>)?),
|
| 874 | @fields($($fields)*),
|
| 875 | @error($err),
|
| 876 | )
|
| 877 | };
|
| 878 | (
|
| 879 | @this($($this:ident)?),
|
| 880 | @typ($t:ident $(::<$($generics:ty),*>)?),
|
| 881 | @fields($($fields:tt)*),
|
| 882 | @error($err:ty),
|
| 883 | ) => {{
|
| 884 | |
| 885 | |
| 886 | |
| 887 | struct __InitOk;
|
| 888 | |
| 889 | let data = unsafe {
|
| 890 | use $crate::init::__internal::HasInitData;
|
| 891 | $t$(::<$($generics),*>)?::__init_data()
|
| 892 | };
|
| 893 | |
| 894 | let init = $crate::init::__internal::InitData::make_closure::<_, __InitOk, $err>(
|
| 895 | data,
|
| 896 | move |slot| {
|
| 897 | {
|
| 898 | |
| 899 | struct __InitOk;
|
| 900 | |
| 901 | |
| 902 | $(let $this = unsafe { ::core::ptr::NonNull::new_unchecked(slot) };)?
|
| 903 | |
| 904 | $crate::try_init!(init_slot:
|
| 905 | @slot(slot),
|
| 906 | @munch_fields($($fields)*,),
|
| 907 | );
|
| 908 | |
| 909 | |
| 910 | |
| 911 | #[allow(unreachable_code, clippy::diverging_sub_expression)]
|
| 912 | if false {
|
| 913 | $crate::try_init!(make_initializer:
|
| 914 | @slot(slot),
|
| 915 | @type_name($t),
|
| 916 | @munch_fields($($fields)*,),
|
| 917 | @acc(),
|
| 918 | );
|
| 919 | }
|
| 920 | |
| 921 | $crate::try_init!(forget_guards:
|
| 922 | @munch_fields($($fields)*,),
|
| 923 | );
|
| 924 | }
|
| 925 | Ok(__InitOk)
|
| 926 | }
|
| 927 | );
|
| 928 | let init = move |slot| -> ::core::result::Result<(), $err> {
|
| 929 | init(slot).map(|__InitOk| ())
|
| 930 | };
|
| 931 | let init = unsafe { $crate::init::init_from_closure::<_, $err>(init) };
|
| 932 | init
|
| 933 | }};
|
| 934 | (init_slot:
|
| 935 | @slot($slot:ident),
|
| 936 | @munch_fields( $(,)?),
|
| 937 | ) => {
|
| 938 | |
| 939 | };
|
| 940 | (init_slot:
|
| 941 | @slot($slot:ident),
|
| 942 | @munch_fields($field:ident <- $val:expr, $($rest:tt)*),
|
| 943 | ) => {
|
| 944 | let $field = $val;
|
| 945 | |
| 946 | |
| 947 | |
| 948 | |
| 949 | unsafe {
|
| 950 | $crate::init::Init::__init($field, ::core::ptr::addr_of_mut!((*$slot).$field))?;
|
| 951 | }
|
| 952 | |
| 953 | |
| 954 | |
| 955 | |
| 956 | |
| 957 | let $field = &unsafe {
|
| 958 | $crate::init::__internal::DropGuard::new(::core::ptr::addr_of_mut!((*$slot).$field))
|
| 959 | };
|
| 960 |
|
| 961 | $crate::try_init!(init_slot:
|
| 962 | @slot($slot),
|
| 963 | @munch_fields($($rest)*),
|
| 964 | );
|
| 965 | };
|
| 966 | (init_slot:
|
| 967 | @slot($slot:ident),
|
| 968 | |
| 969 | @munch_fields($field:ident $(: $val:expr)?, $($rest:tt)*),
|
| 970 | ) => {
|
| 971 | $(let $field = $val;)?
|
| 972 | |
| 973 | |
| 974 | |
| 975 | unsafe { ::core::ptr::write(::core::ptr::addr_of_mut!((*$slot).$field), $field) };
|
| 976 | |
| 977 | |
| 978 | |
| 979 | |
| 980 | |
| 981 | let $field = &unsafe {
|
| 982 | $crate::init::__internal::DropGuard::new(::core::ptr::addr_of_mut!((*$slot).$field))
|
| 983 | };
|
| 984 |
|
| 985 | $crate::try_init!(init_slot:
|
| 986 | @slot($slot),
|
| 987 | @munch_fields($($rest)*),
|
| 988 | );
|
| 989 | };
|
| 990 | (make_initializer:
|
| 991 | @slot($slot:ident),
|
| 992 | @type_name($t:ident),
|
| 993 | @munch_fields( $(,)?),
|
| 994 | @acc($($acc:tt)*),
|
| 995 | ) => {
|
| 996 | |
| 997 | |
| 998 | |
| 999 | unsafe {
|
| 1000 | ::core::ptr::write($slot, $t {
|
| 1001 | $($acc)*
|
| 1002 | });
|
| 1003 | }
|
| 1004 | };
|
| 1005 | (make_initializer:
|
| 1006 | @slot($slot:ident),
|
| 1007 | @type_name($t:ident),
|
| 1008 | @munch_fields($field:ident <- $val:expr, $($rest:tt)*),
|
| 1009 | @acc($($acc:tt)*),
|
| 1010 | ) => {
|
| 1011 | $crate::try_init!(make_initializer:
|
| 1012 | @slot($slot),
|
| 1013 | @type_name($t),
|
| 1014 | @munch_fields($($rest)*),
|
| 1015 | @acc($($acc)*$field: ::core::panic!(),),
|
| 1016 | );
|
| 1017 | };
|
| 1018 | (make_initializer:
|
| 1019 | @slot($slot:ident),
|
| 1020 | @type_name($t:ident),
|
| 1021 | @munch_fields($field:ident $(: $val:expr)?, $($rest:tt)*),
|
| 1022 | @acc($($acc:tt)*),
|
| 1023 | ) => {
|
| 1024 | $crate::try_init!(make_initializer:
|
| 1025 | @slot($slot),
|
| 1026 | @type_name($t),
|
| 1027 | @munch_fields($($rest)*),
|
| 1028 | @acc($($acc)*$field: ::core::panic!(),),
|
| 1029 | );
|
| 1030 | };
|
| 1031 | (forget_guards:
|
| 1032 | @munch_fields($(,)?),
|
| 1033 | ) => {
|
| 1034 | |
| 1035 | };
|
| 1036 | (forget_guards:
|
| 1037 | @munch_fields($field:ident <- $val:expr, $($rest:tt)*),
|
| 1038 | ) => {
|
| 1039 | unsafe { $crate::init::__internal::DropGuard::forget($field) };
|
| 1040 |
|
| 1041 | $crate::try_init!(forget_guards:
|
| 1042 | @munch_fields($($rest)*),
|
| 1043 | );
|
| 1044 | };
|
| 1045 | (forget_guards:
|
| 1046 | @munch_fields($field:ident $(: $val:expr)?, $($rest:tt)*),
|
| 1047 | ) => {
|
| 1048 | unsafe { $crate::init::__internal::DropGuard::forget($field) };
|
| 1049 |
|
| 1050 | $crate::try_init!(forget_guards:
|
| 1051 | @munch_fields($($rest)*),
|
| 1052 | );
|
| 1053 | };
|
| 1054 | }
|
| 1055 |
|
| 1056 | |
| 1057 | |
| 1058 | |
| 1059 | |
| 1060 | |
| 1061 | |
| 1062 | |
| 1063 | |
| 1064 | |
| 1065 | |
| 1066 | |
| 1067 | |
| 1068 | |
| 1069 | |
| 1070 | |
| 1071 | |
| 1072 | |
| 1073 | |
| 1074 | |
| 1075 | |
| 1076 | |
| 1077 | |
| 1078 | |
| 1079 | #[must_use = "An initializer must be used in order to create its value."]
|
| 1080 | pub unsafe trait PinInit<T: ?Sized, E = Infallible>: Sized {
|
| 1081 | |
| 1082 | |
| 1083 | |
| 1084 | |
| 1085 | |
| 1086 | |
| 1087 | |
| 1088 | |
| 1089 | unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E>;
|
| 1090 | }
|
| 1091 |
|
| 1092 | |
| 1093 | |
| 1094 | |
| 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 | #[must_use = "An initializer must be used in order to create its value."]
|
| 1122 | pub unsafe trait Init<T: ?Sized, E = Infallible>: Sized {
|
| 1123 | |
| 1124 | |
| 1125 | |
| 1126 | |
| 1127 | |
| 1128 | |
| 1129 | |
| 1130 | unsafe fn __init(self, slot: *mut T) -> Result<(), E>;
|
| 1131 | }
|
| 1132 |
|
| 1133 | |
| 1134 | unsafe impl<T: ?Sized, E, I> PinInit<T, E> for I
|
| 1135 | where
|
| 1136 | I: Init<T, E>,
|
| 1137 | {
|
| 1138 | unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> {
|
| 1139 | |
| 1140 | |
| 1141 | unsafe { self.__init(slot) }
|
| 1142 | }
|
| 1143 | }
|
| 1144 |
|
| 1145 | |
| 1146 | |
| 1147 | |
| 1148 | |
| 1149 | |
| 1150 | |
| 1151 | |
| 1152 | |
| 1153 | |
| 1154 | |
| 1155 | |
| 1156 | |
| 1157 | #[inline]
|
| 1158 | pub const unsafe fn pin_init_from_closure<T: ?Sized, E>(
|
| 1159 | f: impl FnOnce(*mut T) -> Result<(), E>,
|
| 1160 | ) -> impl PinInit<T, E> {
|
| 1161 | __internal::InitClosure(f, PhantomData)
|
| 1162 | }
|
| 1163 |
|
| 1164 | |
| 1165 | |
| 1166 | |
| 1167 | |
| 1168 | |
| 1169 | |
| 1170 | |
| 1171 | |
| 1172 | |
| 1173 | |
| 1174 | |
| 1175 | |
| 1176 | #[inline]
|
| 1177 | pub const unsafe fn init_from_closure<T: ?Sized, E>(
|
| 1178 | f: impl FnOnce(*mut T) -> Result<(), E>,
|
| 1179 | ) -> impl Init<T, E> {
|
| 1180 | __internal::InitClosure(f, PhantomData)
|
| 1181 | }
|
| 1182 |
|
| 1183 | |
| 1184 | |
| 1185 | |
| 1186 | #[inline]
|
| 1187 | pub fn uninit<T, E>() -> impl Init<MaybeUninit<T>, E> {
|
| 1188 | |
| 1189 | unsafe { init_from_closure(|_| Ok(())) }
|
| 1190 | }
|
| 1191 |
|
| 1192 | |
| 1193 | unsafe impl<T, E> Init<T, E> for T {
|
| 1194 | unsafe fn __init(self, slot: *mut T) -> Result<(), E> {
|
| 1195 | unsafe { slot.write(self) };
|
| 1196 | Ok(())
|
| 1197 | }
|
| 1198 | }
|
| 1199 |
|
| 1200 | |
| 1201 | pub trait InPlaceInit<T>: Sized {
|
| 1202 | |
| 1203 | |
| 1204 | |
| 1205 | |
| 1206 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E>
|
| 1207 | where
|
| 1208 | E: From<AllocError>;
|
| 1209 |
|
| 1210 | |
| 1211 | |
| 1212 | |
| 1213 | |
| 1214 | fn pin_init<E>(init: impl PinInit<T, E>) -> error::Result<Pin<Self>>
|
| 1215 | where
|
| 1216 | Error: From<E>,
|
| 1217 | {
|
| 1218 | |
| 1219 | let init = unsafe {
|
| 1220 | pin_init_from_closure(|slot| init.__pinned_init(slot).map_err(|e| Error::from(e)))
|
| 1221 | };
|
| 1222 | Self::try_pin_init(init)
|
| 1223 | }
|
| 1224 |
|
| 1225 | |
| 1226 | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E>
|
| 1227 | where
|
| 1228 | E: From<AllocError>;
|
| 1229 |
|
| 1230 | |
| 1231 | fn init<E>(init: impl Init<T, E>) -> error::Result<Self>
|
| 1232 | where
|
| 1233 | Error: From<E>,
|
| 1234 | {
|
| 1235 | |
| 1236 | let init = unsafe {
|
| 1237 | init_from_closure(|slot| init.__pinned_init(slot).map_err(|e| Error::from(e)))
|
| 1238 | };
|
| 1239 | Self::try_init(init)
|
| 1240 | }
|
| 1241 | }
|
| 1242 |
|
| 1243 | impl<T> InPlaceInit<T> for Box<T> {
|
| 1244 | #[inline]
|
| 1245 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E>
|
| 1246 | where
|
| 1247 | E: From<AllocError>,
|
| 1248 | {
|
| 1249 | let mut this = Box::try_new_uninit()?;
|
| 1250 | let slot = this.as_mut_ptr();
|
| 1251 | |
| 1252 | |
| 1253 | unsafe { init.__pinned_init(slot)? };
|
| 1254 | |
| 1255 | Ok(unsafe { this.assume_init() }.into())
|
| 1256 | }
|
| 1257 |
|
| 1258 | #[inline]
|
| 1259 | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E>
|
| 1260 | where
|
| 1261 | E: From<AllocError>,
|
| 1262 | {
|
| 1263 | let mut this = Box::try_new_uninit()?;
|
| 1264 | let slot = this.as_mut_ptr();
|
| 1265 | |
| 1266 | |
| 1267 | unsafe { init.__init(slot)? };
|
| 1268 | |
| 1269 | Ok(unsafe { this.assume_init() })
|
| 1270 | }
|
| 1271 | }
|
| 1272 |
|
| 1273 | impl<T> InPlaceInit<T> for UniqueArc<T> {
|
| 1274 | #[inline]
|
| 1275 | fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E>
|
| 1276 | where
|
| 1277 | E: From<AllocError>,
|
| 1278 | {
|
| 1279 | let mut this = UniqueArc::try_new_uninit()?;
|
| 1280 | let slot = this.as_mut_ptr();
|
| 1281 | |
| 1282 | |
| 1283 | unsafe { init.__pinned_init(slot)? };
|
| 1284 | |
| 1285 | Ok(unsafe { this.assume_init() }.into())
|
| 1286 | }
|
| 1287 |
|
| 1288 | #[inline]
|
| 1289 | fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E>
|
| 1290 | where
|
| 1291 | E: From<AllocError>,
|
| 1292 | {
|
| 1293 | let mut this = UniqueArc::try_new_uninit()?;
|
| 1294 | let slot = this.as_mut_ptr();
|
| 1295 | |
| 1296 | |
| 1297 | unsafe { init.__init(slot)? };
|
| 1298 | |
| 1299 | Ok(unsafe { this.assume_init() })
|
| 1300 | }
|
| 1301 | }
|
| 1302 |
|
| 1303 | |
| 1304 | |
| 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 | pub unsafe trait PinnedDrop: __internal::HasPinData {
|
| 1331 | |
| 1332 | |
| 1333 | |
| 1334 | |
| 1335 | |
| 1336 | |
| 1337 | |
| 1338 | |
| 1339 | fn drop(self: Pin<&mut Self>, only_call_from_drop: __internal::OnlyCallFromDrop);
|
| 1340 | }
|
| 1341 |
|
| 1342 | |
| 1343 | |
| 1344 | |
| 1345 | |
| 1346 | |
| 1347 | |
| 1348 | |
| 1349 | |
| 1350 | |
| 1351 | |
| 1352 | pub unsafe trait Zeroable {}
|
| 1353 |
|
| 1354 | |
| 1355 | |
| 1356 | |
| 1357 | #[inline]
|
| 1358 | pub fn zeroed<T: Zeroable>() -> impl Init<T> {
|
| 1359 | |
| 1360 | |
| 1361 | unsafe {
|
| 1362 | init_from_closure(|slot: *mut T| {
|
| 1363 | slot.write_bytes(0, 1);
|
| 1364 | Ok(())
|
| 1365 | })
|
| 1366 | }
|
| 1367 | }
|
| 1368 |
|
| 1369 | macro_rules! impl_zeroable {
|
| 1370 | ($($({$($generics:tt)*})? $t:ty, )*) => {
|
| 1371 | $(unsafe impl$($($generics)*)? Zeroable for $t {})*
|
| 1372 | };
|
| 1373 | }
|
| 1374 |
|
| 1375 | impl_zeroable! {
|
| 1376 | |
| 1377 | bool,
|
| 1378 | char,
|
| 1379 | u8, u16, u32, u64, u128, usize,
|
| 1380 | i8, i16, i32, i64, i128, isize,
|
| 1381 | f32, f64,
|
| 1382 |
|
| 1383 | |
| 1384 | {<T: ?Sized>} PhantomData<T>, core::marker::PhantomPinned, Infallible, (),
|
| 1385 |
|
| 1386 | |
| 1387 | {<T>} MaybeUninit<T>,
|
| 1388 |
|
| 1389 | |
| 1390 | Option<NonZeroU8>, Option<NonZeroU16>, Option<NonZeroU32>, Option<NonZeroU64>,
|
| 1391 | Option<NonZeroU128>, Option<NonZeroUsize>,
|
| 1392 | Option<NonZeroI8>, Option<NonZeroI16>, Option<NonZeroI32>, Option<NonZeroI64>,
|
| 1393 | Option<NonZeroI128>, Option<NonZeroIsize>,
|
| 1394 |
|
| 1395 | |
| 1396 | |
| 1397 | |
| 1398 | {<T: ?Sized>} Option<NonNull<T>>,
|
| 1399 | {<T: ?Sized>} Option<Box<T>>,
|
| 1400 |
|
| 1401 | |
| 1402 | |
| 1403 | |
| 1404 | |
| 1405 | |
| 1406 | |
| 1407 | |
| 1408 | {<T>} *mut T, {<T>} *const T,
|
| 1409 |
|
| 1410 | |
| 1411 | |
| 1412 | {<T>} *mut [T], {<T>} *const [T], *mut str, *const str,
|
| 1413 |
|
| 1414 | |
| 1415 | {<const N: usize, T: Zeroable>} [T; N], {<T: Zeroable>} Wrapping<T>,
|
| 1416 | }
|
| 1417 |
|
| 1418 | macro_rules! impl_tuple_zeroable {
|
| 1419 | ($(,)?) => {};
|
| 1420 | ($first:ident, $($t:ident),* $(,)?) => {
|
| 1421 | // SAFETY: All elements are zeroable and padding can be zero.
|
| 1422 | unsafe impl<$first: Zeroable, $($t: Zeroable),*> Zeroable for ($first, $($t),*) {}
|
| 1423 | impl_tuple_zeroable!($($t),* ,);
|
| 1424 | }
|
| 1425 | }
|
| 1426 |
|
| 1427 | impl_tuple_zeroable!(A, B, C, D, E, F, G, H, I, J);
|