Skip to content

Commit e4a259b

Browse files
committed
fixup! docs: Improve AsRef / AsMut docs on blanket impls
Better conform to Rust API Documentation Conventions
1 parent 9f68e3e commit e4a259b

File tree

1 file changed

+14
-7
lines changed
  • library/core/src/convert

1 file changed

+14
-7
lines changed

library/core/src/convert/mod.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ pub const fn identity<T>(x: T) -> T {
146146
/// let y: &i32 = &x;
147147
/// ```
148148
///
149-
/// Types which implement [`Deref`][core::ops::Deref] should consider implementing `AsRef` as
150-
/// follows:
149+
/// Types which implement [`Deref`] should consider implementing `AsRef<T>` as follows:
150+
///
151+
/// [`Deref`]: core::ops::Deref
151152
///
152153
/// ```
153154
/// # use core::ops::Deref;
@@ -172,12 +173,14 @@ pub const fn identity<T>(x: T) -> T {
172173
/// # Reflexivity
173174
///
174175
/// Ideally, `AsRef` would be reflexive, that is there is an `impl<T: ?Sized> AsRef<T> for T`, with
175-
/// [`as_ref`][AsRef::as_ref] simply returning its argument unchanged.
176+
/// [`as_ref`] simply returning its argument unchanged.
176177
/// Such a blanket implementation is currently *not* provided due to technical restrictions of
177178
/// Rust's type system (it would be overlapping with another existing blanket implementation for
178179
/// `&T where T: AsRef<U>` which allows `AsRef` to auto-dereference, see "Generic Implementations"
179180
/// above).
180181
///
182+
/// [`as_ref`]: AsRef::as_ref
183+
///
181184
/// A trivial implementation of `AsRef<T> for T` must be added explicitly for a particular type `T`
182185
/// where needed or desired. Note, however, that not all types from `std` contain such an
183186
/// implementation, and those cannot be added by external code due to orphan rules.
@@ -249,8 +252,10 @@ pub trait AsRef<T: ?Sized> {
249252
/// let y: &mut i32 = &mut x;
250253
/// ```
251254
///
252-
/// Types which implement [`DerefMut`](core::ops::DerefMut) should consider to add an
253-
/// implementation of `AsMut` as follows:
255+
/// Types which implement [`DerefMut`] should consider to add an implementation of `AsMut<T>` as
256+
/// follows:
257+
///
258+
/// [`DerefMut`]: core::ops::DerefMut
254259
///
255260
/// ```
256261
/// # use core::ops::{Deref, DerefMut};
@@ -279,12 +284,14 @@ pub trait AsRef<T: ?Sized> {
279284
/// # Reflexivity
280285
///
281286
/// Ideally, `AsMut` would be reflexive, that is there is an `impl<T: ?Sized> AsMut<T> for T`, with
282-
/// [`as_mut`][AsMut::as_mut] simply returning its argument unchanged.
287+
/// [`as_mut`] simply returning its argument unchanged.
283288
/// Such a blanket implementation is currently *not* provided due to technical restrictions of
284289
/// Rust's type system (it would be overlapping with another existing blanket implementation for
285290
/// `&mut T where T: AsMut<U>` which allows `AsMut` to auto-dereference, see "Generic
286291
/// Implementations" above).
287292
///
293+
/// [`as_mut`]: AsMut::as_mut
294+
///
288295
/// A trivial implementation of `AsMut<T> for T` must be added explicitly for a particular type `T`
289296
/// where needed or desired. Note, however, that not all types from `std` contain such an
290297
/// implementation, and those cannot be added by external code due to orphan rules.
@@ -298,7 +305,7 @@ pub trait AsRef<T: ?Sized> {
298305
///
299306
/// In the following, the example functions `caesar` and `null_terminate` provide a generic
300307
/// interface which work with any type that can be converted by cheap mutable-to-mutable conversion
301-
/// into a byte slice or byte `Vec`, respectively.
308+
/// into a byte slice (`[u8]`) or byte vector (`Vec<u8>`), respectively.
302309
///
303310
/// [dereference]: core::ops::DerefMut
304311
/// [target type]: core::ops::Deref::Target

0 commit comments

Comments
 (0)