146146//!
147147//! impl DriverData {
148148//! fn new() -> impl PinInit<Self, Error> {
149- //! try_pin_init !(Self {
149+ //! pin_init !(Self {
150150//! status <- CMutex::new(0),
151151//! buffer: Box::init(pin_init::init_zeroed())?,
152152//! }? Error)
@@ -528,7 +528,7 @@ macro_rules! stack_pin_init {
528528/// x: u32,
529529/// }
530530///
531- /// stack_try_pin_init!(let foo: Foo = try_pin_init !(Foo {
531+ /// stack_try_pin_init!(let foo: Foo = pin_init !(Foo {
532532/// a <- CMutex::new(42),
533533/// b: Box::try_new(Bar {
534534/// x: 64,
@@ -555,7 +555,7 @@ macro_rules! stack_pin_init {
555555/// x: u32,
556556/// }
557557///
558- /// stack_try_pin_init!(let foo: Foo =? try_pin_init !(Foo {
558+ /// stack_try_pin_init!(let foo: Foo =? pin_init !(Foo {
559559/// a <- CMutex::new(42),
560560/// b: Box::try_new(Bar {
561561/// x: 64,
@@ -584,10 +584,10 @@ macro_rules! stack_try_pin_init {
584584 } ;
585585}
586586
587- /// Construct an in-place, pinned initializer for `struct`s.
587+ /// Construct an in-place, fallible pinned initializer for `struct`s.
588588///
589- /// This macro defaults the error to [`Infallible`]. If you need a different error, then use
590- /// [`try_pin_init!`] .
589+ /// The error type defaults to [`Infallible`]; if you need a different one, write `? Error` at the
590+ /// end, after the struct initializer .
591591///
592592/// The syntax is almost identical to that of a normal `struct` initializer:
593593///
@@ -783,54 +783,10 @@ macro_rules! pin_init {
783783 ( $( & $this: ident in) ? $t: ident $( :: <$( $generics: ty) ,* $( , ) ?>) ? {
784784 $( $fields: tt) *
785785 } ) => {
786- $crate:: try_pin_init !( $( & $this in) ? $t $( :: <$( $generics) ,* >) ? {
786+ $crate:: pin_init !( $( & $this in) ? $t $( :: <$( $generics) ,* >) ? {
787787 $( $fields) *
788788 } ? :: core:: convert:: Infallible )
789789 } ;
790- }
791-
792- /// Construct an in-place, fallible pinned initializer for `struct`s.
793- ///
794- /// If the initialization can complete without error (or [`Infallible`]), then use [`pin_init!`].
795- ///
796- /// You can use the `?` operator or use `return Err(err)` inside the initializer to stop
797- /// initialization and return the error.
798- ///
799- /// IMPORTANT: if you have `unsafe` code inside of the initializer you have to ensure that when
800- /// initialization fails, the memory can be safely deallocated without any further modifications.
801- ///
802- /// The syntax is identical to [`pin_init!`] with the following exception: you must append `? $type`
803- /// after the `struct` initializer to specify the error type you want to use.
804- ///
805- /// # Examples
806- ///
807- /// ```rust
808- /// # #![feature(allocator_api)]
809- /// # #[path = "../examples/error.rs"] mod error; use error::Error;
810- /// use pin_init::{pin_data, try_pin_init, PinInit, InPlaceInit, init_zeroed};
811- ///
812- /// #[pin_data]
813- /// struct BigBuf {
814- /// big: Box<[u8; 1024 * 1024 * 1024]>,
815- /// small: [u8; 1024 * 1024],
816- /// ptr: *mut u8,
817- /// }
818- ///
819- /// impl BigBuf {
820- /// fn new() -> impl PinInit<Self, Error> {
821- /// try_pin_init!(Self {
822- /// big: Box::init(init_zeroed())?,
823- /// small: [0; 1024 * 1024],
824- /// ptr: core::ptr::null_mut(),
825- /// }? Error)
826- /// }
827- /// }
828- /// # let _ = Box::pin_init(BigBuf::new());
829- /// ```
830- // For a detailed example of how this macro works, see the module documentation of the hidden
831- // module `macros` inside of `macros.rs`.
832- #[ macro_export]
833- macro_rules! try_pin_init {
834790 ( $( & $this: ident in) ? $t: ident $( :: <$( $generics: ty) ,* $( , ) ?>) ? {
835791 $( $fields: tt) *
836792 } ? $err: ty) => {
@@ -847,10 +803,10 @@ macro_rules! try_pin_init {
847803 }
848804}
849805
850- /// Construct an in-place initializer for `struct`s.
806+ /// Construct an in-place, fallible initializer for `struct`s.
851807///
852- /// This macro defaults the error to [`Infallible`]. If you need a different error, then use
853- /// [`try_init!`] .
808+ /// This macro defaults the error to [`Infallible`]; if you need a different one, write `? Error`
809+ /// at the end, after the struct initializer .
854810///
855811/// The syntax is identical to [`pin_init!`] and its safety caveats also apply:
856812/// - `unsafe` code must guarantee either full initialization or return an error and allow
@@ -890,52 +846,10 @@ macro_rules! init {
890846 ( $( & $this: ident in) ? $t: ident $( :: <$( $generics: ty) ,* $( , ) ?>) ? {
891847 $( $fields: tt) *
892848 } ) => {
893- $crate:: try_init !( $( & $this in) ? $t $( :: <$( $generics) ,* >) ? {
849+ $crate:: init !( $( & $this in) ? $t $( :: <$( $generics) ,* >) ? {
894850 $( $fields) *
895851 } ? :: core:: convert:: Infallible )
896- }
897- }
898-
899- /// Construct an in-place fallible initializer for `struct`s.
900- ///
901- /// If the initialization can complete without error (or [`Infallible`]), then use
902- /// [`init!`].
903- ///
904- /// The syntax is identical to [`try_pin_init!`]. You need to specify a custom error
905- /// via `? $type` after the `struct` initializer.
906- /// The safety caveats from [`try_pin_init!`] also apply:
907- /// - `unsafe` code must guarantee either full initialization or return an error and allow
908- /// deallocation of the memory.
909- /// - the fields are initialized in the order given in the initializer.
910- /// - no references to fields are allowed to be created inside of the initializer.
911- ///
912- /// # Examples
913- ///
914- /// ```rust
915- /// # #![feature(allocator_api)]
916- /// # use core::alloc::AllocError;
917- /// # use pin_init::InPlaceInit;
918- /// use pin_init::{try_init, Init, init_zeroed};
919- ///
920- /// struct BigBuf {
921- /// big: Box<[u8; 1024 * 1024 * 1024]>,
922- /// small: [u8; 1024 * 1024],
923- /// }
924- ///
925- /// impl BigBuf {
926- /// fn new() -> impl Init<Self, AllocError> {
927- /// try_init!(Self {
928- /// big: Box::init(init_zeroed())?,
929- /// small: [0; 1024 * 1024],
930- /// }? AllocError)
931- /// }
932- /// }
933- /// # let _ = Box::init(BigBuf::new());
934- /// ```
935- // For a detailed example of how this macro works, see the module documentation of the hidden
936- // module `macros` inside of `macros.rs`.
937- #[ macro_export]
938- macro_rules! try_init {
852+ } ;
939853 ( $( & $this: ident in) ? $t: ident $( :: <$( $generics: ty) ,* $( , ) ?>) ? {
940854 $( $fields: tt) *
941855 } ? $err: ty) => {
@@ -1410,14 +1324,14 @@ where
14101324/// fn init_foo() -> impl PinInit<Foo, Error> {
14111325/// pin_init_scope(|| {
14121326/// let bar = lookup_bar()?;
1413- /// Ok(try_pin_init !(Foo { a: bar.a.into(), b: bar.b }? Error))
1327+ /// Ok(pin_init !(Foo { a: bar.a.into(), b: bar.b }? Error))
14141328/// })
14151329/// }
14161330/// ```
14171331///
14181332/// This initializer will first execute `lookup_bar()`, match on it, if it returned an error, the
14191333/// initializer itself will fail with that error. If it returned `Ok`, then it will run the
1420- /// initializer returned by the [`try_pin_init !`] invocation.
1334+ /// initializer returned by the [`pin_init !`] invocation.
14211335pub fn pin_init_scope < T , E , F , I > ( make_init : F ) -> impl PinInit < T , E >
14221336where
14231337 F : FnOnce ( ) -> Result < I , E > ,
@@ -1453,14 +1367,14 @@ where
14531367/// fn init_foo() -> impl Init<Foo, Error> {
14541368/// init_scope(|| {
14551369/// let bar = lookup_bar()?;
1456- /// Ok(try_init !(Foo { a: bar.a.into(), b: bar.b }? Error))
1370+ /// Ok(init !(Foo { a: bar.a.into(), b: bar.b }? Error))
14571371/// })
14581372/// }
14591373/// ```
14601374///
14611375/// This initializer will first execute `lookup_bar()`, match on it, if it returned an error, the
14621376/// initializer itself will fail with that error. If it returned `Ok`, then it will run the
1463- /// initializer returned by the [`try_init !`] invocation.
1377+ /// initializer returned by the [`init !`] invocation.
14641378pub fn init_scope < T , E , F , I > ( make_init : F ) -> impl Init < T , E >
14651379where
14661380 F : FnOnce ( ) -> Result < I , E > ,
0 commit comments