@@ -135,28 +135,9 @@ impl<T: PointeeSized> *mut T {
135
135
self as _
136
136
}
137
137
138
- /// Gets the "address" portion of the pointer.
139
- ///
140
- /// This is similar to `self as usize`, except that the [provenance][crate::ptr#provenance] of
141
- /// the pointer is discarded and not [exposed][crate::ptr#exposed-provenance]. This means that
142
- /// casting the returned address back to a pointer yields a [pointer without
143
- /// provenance][without_provenance_mut], which is undefined behavior to dereference. To properly
144
- /// restore the lost information and obtain a dereferenceable pointer, use
145
- /// [`with_addr`][pointer::with_addr] or [`map_addr`][pointer::map_addr].
146
- ///
147
- /// If using those APIs is not possible because there is no way to preserve a pointer with the
148
- /// required provenance, then Strict Provenance might not be for you. Use pointer-integer casts
149
- /// or [`expose_provenance`][pointer::expose_provenance] and [`with_exposed_provenance`][with_exposed_provenance]
150
- /// instead. However, note that this makes your code less portable and less amenable to tools
151
- /// that check for compliance with the Rust memory model.
152
- ///
153
- /// On most platforms this will produce a value with the same bytes as the original
154
- /// pointer, because all the bytes are dedicated to describing the address.
155
- /// Platforms which need to store additional information in the pointer may
156
- /// perform a change of representation to produce a value containing only the address
157
- /// portion of the pointer. What that means is up to the platform to define.
138
+ #[ doc = include_str ! ( "./docs/addr.md" ) ]
158
139
///
159
- /// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
140
+ /// [without_provenance]: without_provenance_mut
160
141
#[ must_use]
161
142
#[ inline( always) ]
162
143
#[ stable( feature = "strict_provenance" , since = "1.84.0" ) ]
@@ -243,26 +224,16 @@ impl<T: PointeeSized> *mut T {
243
224
( self . cast ( ) , super :: metadata ( self ) )
244
225
}
245
226
246
- /// Returns `None` if the pointer is null, or else returns a shared reference to
247
- /// the value wrapped in `Some`. If the value may be uninitialized, [`as_uninit_ref`]
248
- /// must be used instead.
249
- ///
250
- /// For the mutable counterpart see [`as_mut`].
227
+ #[ doc = include_str ! ( "./docs/as_ref.md" ) ]
251
228
///
252
- /// [`as_uninit_ref`]: pointer#method.as_uninit_ref-1
253
- /// [`as_mut`]: #method.as_mut
254
- ///
255
- /// # Safety
256
- ///
257
- /// When calling this method, you have to ensure that *either* the pointer is null *or*
258
- /// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
259
- ///
260
- /// # Panics during const evaluation
261
- ///
262
- /// This method will panic during const evaluation if the pointer cannot be
263
- /// determined to be null or not. See [`is_null`] for more information.
229
+ /// ```
230
+ /// let ptr: *mut u8 = &mut 10u8 as *mut u8;
264
231
///
265
- /// [`is_null`]: #method.is_null-1
232
+ /// unsafe {
233
+ /// let val_back = &*ptr;
234
+ /// println!("We got back the value: {val_back}!");
235
+ /// }
236
+ /// ```
266
237
///
267
238
/// # Examples
268
239
///
@@ -276,20 +247,14 @@ impl<T: PointeeSized> *mut T {
276
247
/// }
277
248
/// ```
278
249
///
279
- /// # Null-unchecked version
280
- ///
281
- /// If you are sure the pointer can never be null and are looking for some kind of
282
- /// `as_ref_unchecked` that returns the `&T` instead of `Option<&T>`, know that you can
283
- /// dereference the pointer directly.
250
+ /// # See Also
284
251
///
285
- /// ```
286
- /// let ptr: *mut u8 = &mut 10u8 as *mut u8;
252
+ /// For the mutable counterpart see [`as_mut`].
287
253
///
288
- /// unsafe {
289
- /// let val_back = &*ptr;
290
- /// println!("We got back the value: {val_back}!");
291
- /// }
292
- /// ```
254
+ /// [`is_null`]: #method.is_null-1
255
+ /// [`as_uninit_ref`]: pointer#method.as_uninit_ref-1
256
+ /// [`as_mut`]: #method.as_mut
257
+
293
258
#[ stable( feature = "ptr_as_ref" , since = "1.9.0" ) ]
294
259
#[ rustc_const_stable( feature = "const_ptr_is_null" , since = "1.84.0" ) ]
295
260
#[ inline]
@@ -332,28 +297,15 @@ impl<T: PointeeSized> *mut T {
332
297
unsafe { & * self }
333
298
}
334
299
335
- /// Returns `None` if the pointer is null, or else returns a shared reference to
336
- /// the value wrapped in `Some`. In contrast to [`as_ref`], this does not require
337
- /// that the value has to be initialized.
338
- ///
339
- /// For the mutable counterpart see [`as_uninit_mut`].
300
+ #[ doc = include_str ! ( "./docs/as_uninit_ref.md" ) ]
340
301
///
302
+ /// [`is_null`]: #method.is_null-1
341
303
/// [`as_ref`]: pointer#method.as_ref-1
342
- /// [`as_uninit_mut`]: #method.as_uninit_mut
343
- ///
344
- /// # Safety
345
- ///
346
- /// When calling this method, you have to ensure that *either* the pointer is null *or*
347
- /// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
348
- /// Note that because the created reference is to `MaybeUninit<T>`, the
349
- /// source pointer can point to uninitialized memory.
350
- ///
351
- /// # Panics during const evaluation
352
304
///
353
- /// This method will panic during const evaluation if the pointer cannot be
354
- /// determined to be null or not. See [`is_null`] for more information .
305
+ /// # See Also
306
+ /// For the mutable counterpart see [`as_uninit_mut`] .
355
307
///
356
- /// [`is_null `]: #method.is_null-1
308
+ /// [`as_uninit_mut `]: #method.as_uninit_mut
357
309
///
358
310
/// # Examples
359
311
///
0 commit comments