1010//! To initialize a `struct` with an in-place constructor you will need two things:
1111//! - an in-place constructor,
1212//! - a memory location that can hold your `struct` (this can be the [stack], an [`Arc<T>`],
13- //! [`UniqueArc<T>`], [` KBox<T>`] or any other smart pointer that implements [`InPlaceInit`] ).
13+ //! [`KBox<T>`] or any other smart pointer that supports this library ).
1414//!
1515//! To get an in-place constructor there are generally three options:
1616//! - directly creating an in-place constructor using the [`pin_init!`] macro,
212212//! [`pin_init!`]: crate::pin_init!
213213
214214use crate :: {
215- alloc:: { AllocError , Flags , KBox } ,
216- error:: { self , Error } ,
217- sync:: Arc ,
218- sync:: UniqueArc ,
215+ alloc:: KBox ,
219216 types:: { Opaque , ScopeGuard } ,
220217} ;
221218use core:: {
@@ -891,8 +888,7 @@ macro_rules! assert_pinned {
891888/// A pin-initializer for the type `T`.
892889///
893890/// To use this initializer, you will need a suitable memory location that can hold a `T`. This can
894- /// be [`KBox<T>`], [`Arc<T>`], [`UniqueArc<T>`] or even the stack (see [`stack_pin_init!`]). Use
895- /// the [`InPlaceInit::pin_init`] function of a smart pointer like [`Arc<T>`] on this.
891+ /// be [`KBox<T>`], [`Arc<T>`] or even the stack (see [`stack_pin_init!`]).
896892///
897893/// Also see the [module description](self).
898894///
@@ -910,7 +906,6 @@ macro_rules! assert_pinned {
910906/// - while constructing the `T` at `slot` it upholds the pinning invariants of `T`.
911907///
912908/// [`Arc<T>`]: crate::sync::Arc
913- /// [`Arc::pin_init`]: crate::sync::Arc::pin_init
914909#[ must_use = "An initializer must be used in order to create its value." ]
915910pub unsafe trait PinInit < T : ?Sized , E = Infallible > : Sized {
916911 /// Initializes `slot`.
@@ -976,8 +971,7 @@ where
976971/// An initializer for `T`.
977972///
978973/// To use this initializer, you will need a suitable memory location that can hold a `T`. This can
979- /// be [`KBox<T>`], [`Arc<T>`], [`UniqueArc<T>`] or even the stack (see [`stack_pin_init!`]). Use
980- /// the [`InPlaceInit::init`] function of a smart pointer like [`Arc<T>`] on this. Because
974+ /// be [`KBox<T>`], [`Arc<T>`] or even the stack (see [`stack_pin_init!`]). Because
981975/// [`PinInit<T, E>`] is a super trait, you can use every function that takes it as well.
982976///
983977/// Also see the [module description](self).
@@ -1238,95 +1232,6 @@ unsafe impl<T, E> PinInit<T, E> for T {
12381232 }
12391233}
12401234
1241- /// Smart pointer that can initialize memory in-place.
1242- pub trait InPlaceInit < T > : Sized {
1243- /// Pinned version of `Self`.
1244- ///
1245- /// If a type already implicitly pins its pointee, `Pin<Self>` is unnecessary. In this case use
1246- /// `Self`, otherwise just use `Pin<Self>`.
1247- type PinnedSelf ;
1248-
1249- /// Use the given pin-initializer to pin-initialize a `T` inside of a new smart pointer of this
1250- /// type.
1251- ///
1252- /// If `T: !Unpin` it will not be able to move afterwards.
1253- fn try_pin_init < E > ( init : impl PinInit < T , E > , flags : Flags ) -> Result < Self :: PinnedSelf , E >
1254- where
1255- E : From < AllocError > ;
1256-
1257- /// Use the given pin-initializer to pin-initialize a `T` inside of a new smart pointer of this
1258- /// type.
1259- ///
1260- /// If `T: !Unpin` it will not be able to move afterwards.
1261- fn pin_init < E > ( init : impl PinInit < T , E > , flags : Flags ) -> error:: Result < Self :: PinnedSelf >
1262- where
1263- Error : From < E > ,
1264- {
1265- // SAFETY: We delegate to `init` and only change the error type.
1266- let init = unsafe {
1267- pin_init_from_closure ( |slot| init. __pinned_init ( slot) . map_err ( |e| Error :: from ( e) ) )
1268- } ;
1269- Self :: try_pin_init ( init, flags)
1270- }
1271-
1272- /// Use the given initializer to in-place initialize a `T`.
1273- fn try_init < E > ( init : impl Init < T , E > , flags : Flags ) -> Result < Self , E >
1274- where
1275- E : From < AllocError > ;
1276-
1277- /// Use the given initializer to in-place initialize a `T`.
1278- fn init < E > ( init : impl Init < T , E > , flags : Flags ) -> error:: Result < Self >
1279- where
1280- Error : From < E > ,
1281- {
1282- // SAFETY: We delegate to `init` and only change the error type.
1283- let init = unsafe {
1284- init_from_closure ( |slot| init. __pinned_init ( slot) . map_err ( |e| Error :: from ( e) ) )
1285- } ;
1286- Self :: try_init ( init, flags)
1287- }
1288- }
1289-
1290- impl < T > InPlaceInit < T > for Arc < T > {
1291- type PinnedSelf = Self ;
1292-
1293- #[ inline]
1294- fn try_pin_init < E > ( init : impl PinInit < T , E > , flags : Flags ) -> Result < Self :: PinnedSelf , E >
1295- where
1296- E : From < AllocError > ,
1297- {
1298- UniqueArc :: try_pin_init ( init, flags) . map ( |u| u. into ( ) )
1299- }
1300-
1301- #[ inline]
1302- fn try_init < E > ( init : impl Init < T , E > , flags : Flags ) -> Result < Self , E >
1303- where
1304- E : From < AllocError > ,
1305- {
1306- UniqueArc :: try_init ( init, flags) . map ( |u| u. into ( ) )
1307- }
1308- }
1309-
1310- impl < T > InPlaceInit < T > for UniqueArc < T > {
1311- type PinnedSelf = Pin < Self > ;
1312-
1313- #[ inline]
1314- fn try_pin_init < E > ( init : impl PinInit < T , E > , flags : Flags ) -> Result < Self :: PinnedSelf , E >
1315- where
1316- E : From < AllocError > ,
1317- {
1318- UniqueArc :: new_uninit ( flags) ?. write_pin_init ( init)
1319- }
1320-
1321- #[ inline]
1322- fn try_init < E > ( init : impl Init < T , E > , flags : Flags ) -> Result < Self , E >
1323- where
1324- E : From < AllocError > ,
1325- {
1326- UniqueArc :: new_uninit ( flags) ?. write_init ( init)
1327- }
1328- }
1329-
13301235/// Smart pointer containing uninitialized memory and that can write a value.
13311236pub trait InPlaceWrite < T > {
13321237 /// The type `Self` turns into when the contents are initialized.
@@ -1343,28 +1248,6 @@ pub trait InPlaceWrite<T> {
13431248 fn write_pin_init < E > ( self , init : impl PinInit < T , E > ) -> Result < Pin < Self :: Initialized > , E > ;
13441249}
13451250
1346- impl < T > InPlaceWrite < T > for UniqueArc < MaybeUninit < T > > {
1347- type Initialized = UniqueArc < T > ;
1348-
1349- fn write_init < E > ( mut self , init : impl Init < T , E > ) -> Result < Self :: Initialized , E > {
1350- let slot = self . as_mut_ptr ( ) ;
1351- // SAFETY: When init errors/panics, slot will get deallocated but not dropped,
1352- // slot is valid.
1353- unsafe { init. __init ( slot) ? } ;
1354- // SAFETY: All fields have been initialized.
1355- Ok ( unsafe { self . assume_init ( ) } )
1356- }
1357-
1358- fn write_pin_init < E > ( mut self , init : impl PinInit < T , E > ) -> Result < Pin < Self :: Initialized > , E > {
1359- let slot = self . as_mut_ptr ( ) ;
1360- // SAFETY: When init errors/panics, slot will get deallocated but not dropped,
1361- // slot is valid and will not be moved, because we pin it later.
1362- unsafe { init. __pinned_init ( slot) ? } ;
1363- // SAFETY: All fields have been initialized.
1364- Ok ( unsafe { self . assume_init ( ) } . into ( ) )
1365- }
1366- }
1367-
13681251/// Trait facilitating pinned destruction.
13691252///
13701253/// Use [`pinned_drop`] to implement this trait safely:
0 commit comments