10
10
//! To initialize a `struct` with an in-place constructor you will need two things:
11
11
//! - an in-place constructor,
12
12
//! - 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 ).
14
14
//!
15
15
//! To get an in-place constructor there are generally three options:
16
16
//! - directly creating an in-place constructor using the [`pin_init!`] macro,
212
212
//! [`pin_init!`]: crate::pin_init!
213
213
214
214
use crate :: {
215
- alloc:: { AllocError , Flags , KBox } ,
216
- error:: { self , Error } ,
217
- sync:: Arc ,
218
- sync:: UniqueArc ,
215
+ alloc:: KBox ,
219
216
types:: { Opaque , ScopeGuard } ,
220
217
} ;
221
218
use core:: {
@@ -891,8 +888,7 @@ macro_rules! assert_pinned {
891
888
/// A pin-initializer for the type `T`.
892
889
///
893
890
/// 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!`]).
896
892
///
897
893
/// Also see the [module description](self).
898
894
///
@@ -910,7 +906,6 @@ macro_rules! assert_pinned {
910
906
/// - while constructing the `T` at `slot` it upholds the pinning invariants of `T`.
911
907
///
912
908
/// [`Arc<T>`]: crate::sync::Arc
913
- /// [`Arc::pin_init`]: crate::sync::Arc::pin_init
914
909
#[ must_use = "An initializer must be used in order to create its value." ]
915
910
pub unsafe trait PinInit < T : ?Sized , E = Infallible > : Sized {
916
911
/// Initializes `slot`.
@@ -976,8 +971,7 @@ where
976
971
/// An initializer for `T`.
977
972
///
978
973
/// 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
981
975
/// [`PinInit<T, E>`] is a super trait, you can use every function that takes it as well.
982
976
///
983
977
/// Also see the [module description](self).
@@ -1238,95 +1232,6 @@ unsafe impl<T, E> PinInit<T, E> for T {
1238
1232
}
1239
1233
}
1240
1234
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
-
1330
1235
/// Smart pointer containing uninitialized memory and that can write a value.
1331
1236
pub trait InPlaceWrite < T > {
1332
1237
/// The type `Self` turns into when the contents are initialized.
@@ -1343,28 +1248,6 @@ pub trait InPlaceWrite<T> {
1343
1248
fn write_pin_init < E > ( self , init : impl PinInit < T , E > ) -> Result < Pin < Self :: Initialized > , E > ;
1344
1249
}
1345
1250
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
-
1368
1251
/// Trait facilitating pinned destruction.
1369
1252
///
1370
1253
/// Use [`pinned_drop`] to implement this trait safely:
0 commit comments