|
213 | 213 | use crate::{
|
214 | 214 | alloc::{box_ext::BoxExt, AllocError, Flags},
|
215 | 215 | error::{self, Error},
|
| 216 | + sync::Arc, |
216 | 217 | sync::UniqueArc,
|
217 | 218 | types::{Opaque, ScopeGuard},
|
218 | 219 | };
|
@@ -1107,19 +1108,25 @@ unsafe impl<T, E> PinInit<T, E> for T {
|
1107 | 1108 |
|
1108 | 1109 | /// Smart pointer that can initialize memory in-place.
|
1109 | 1110 | pub trait InPlaceInit<T>: Sized {
|
| 1111 | + /// Pinned version of `Self`. |
| 1112 | + /// |
| 1113 | + /// If a type already implicitly pins its pointee, `Pin<Self>` is unnecessary. In this case use |
| 1114 | + /// `Self`, otherwise just use `Pin<Self>`. |
| 1115 | + type PinnedSelf; |
| 1116 | + |
1110 | 1117 | /// Use the given pin-initializer to pin-initialize a `T` inside of a new smart pointer of this
|
1111 | 1118 | /// type.
|
1112 | 1119 | ///
|
1113 | 1120 | /// If `T: !Unpin` it will not be able to move afterwards.
|
1114 |
| - fn try_pin_init<E>(init: impl PinInit<T, E>, flags: Flags) -> Result<Pin<Self>, E> |
| 1121 | + fn try_pin_init<E>(init: impl PinInit<T, E>, flags: Flags) -> Result<Self::PinnedSelf, E> |
1115 | 1122 | where
|
1116 | 1123 | E: From<AllocError>;
|
1117 | 1124 |
|
1118 | 1125 | /// Use the given pin-initializer to pin-initialize a `T` inside of a new smart pointer of this
|
1119 | 1126 | /// type.
|
1120 | 1127 | ///
|
1121 | 1128 | /// If `T: !Unpin` it will not be able to move afterwards.
|
1122 |
| - fn pin_init<E>(init: impl PinInit<T, E>, flags: Flags) -> error::Result<Pin<Self>> |
| 1129 | + fn pin_init<E>(init: impl PinInit<T, E>, flags: Flags) -> error::Result<Self::PinnedSelf> |
1123 | 1130 | where
|
1124 | 1131 | Error: From<E>,
|
1125 | 1132 | {
|
@@ -1148,9 +1155,31 @@ pub trait InPlaceInit<T>: Sized {
|
1148 | 1155 | }
|
1149 | 1156 | }
|
1150 | 1157 |
|
| 1158 | +impl<T> InPlaceInit<T> for Arc<T> { |
| 1159 | + type PinnedSelf = Self; |
| 1160 | + |
| 1161 | + #[inline] |
| 1162 | + fn try_pin_init<E>(init: impl PinInit<T, E>, flags: Flags) -> Result<Self::PinnedSelf, E> |
| 1163 | + where |
| 1164 | + E: From<AllocError>, |
| 1165 | + { |
| 1166 | + UniqueArc::try_pin_init(init, flags).map(|u| u.into()) |
| 1167 | + } |
| 1168 | + |
| 1169 | + #[inline] |
| 1170 | + fn try_init<E>(init: impl Init<T, E>, flags: Flags) -> Result<Self, E> |
| 1171 | + where |
| 1172 | + E: From<AllocError>, |
| 1173 | + { |
| 1174 | + UniqueArc::try_init(init, flags).map(|u| u.into()) |
| 1175 | + } |
| 1176 | +} |
| 1177 | + |
1151 | 1178 | impl<T> InPlaceInit<T> for Box<T> {
|
| 1179 | + type PinnedSelf = Pin<Self>; |
| 1180 | + |
1152 | 1181 | #[inline]
|
1153 |
| - fn try_pin_init<E>(init: impl PinInit<T, E>, flags: Flags) -> Result<Pin<Self>, E> |
| 1182 | + fn try_pin_init<E>(init: impl PinInit<T, E>, flags: Flags) -> Result<Self::PinnedSelf, E> |
1154 | 1183 | where
|
1155 | 1184 | E: From<AllocError>,
|
1156 | 1185 | {
|
@@ -1179,8 +1208,10 @@ impl<T> InPlaceInit<T> for Box<T> {
|
1179 | 1208 | }
|
1180 | 1209 |
|
1181 | 1210 | impl<T> InPlaceInit<T> for UniqueArc<T> {
|
| 1211 | + type PinnedSelf = Pin<Self>; |
| 1212 | + |
1182 | 1213 | #[inline]
|
1183 |
| - fn try_pin_init<E>(init: impl PinInit<T, E>, flags: Flags) -> Result<Pin<Self>, E> |
| 1214 | + fn try_pin_init<E>(init: impl PinInit<T, E>, flags: Flags) -> Result<Self::PinnedSelf, E> |
1184 | 1215 | where
|
1185 | 1216 | E: From<AllocError>,
|
1186 | 1217 | {
|
|
0 commit comments