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