Provide more useful documentation of conversion methods
I thought that the documentation for these methods needed to be a bit more explanatory for new users. For advanced users, the comments are relatively unnecessary. I think it would be useful to explain precisely what the method does. As a new user, when you see the `into` method, where the type is inferred, if you are new you don't even know what you convert to, because it is implicit. I believe this can help new users understand.
This commit is contained in:
parent
3153584170
commit
edee46e257
1 changed files with 4 additions and 4 deletions
|
@ -154,7 +154,7 @@ pub const fn identity<T>(x: T) -> T {
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[cfg_attr(not(test), rustc_diagnostic_item = "AsRef")]
|
#[cfg_attr(not(test), rustc_diagnostic_item = "AsRef")]
|
||||||
pub trait AsRef<T: ?Sized> {
|
pub trait AsRef<T: ?Sized> {
|
||||||
/// Performs the conversion.
|
/// Converts this type into a shared reference of the (usually inferred) input type.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
fn as_ref(&self) -> &T;
|
fn as_ref(&self) -> &T;
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ pub trait AsRef<T: ?Sized> {
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[cfg_attr(not(test), rustc_diagnostic_item = "AsMut")]
|
#[cfg_attr(not(test), rustc_diagnostic_item = "AsMut")]
|
||||||
pub trait AsMut<T: ?Sized> {
|
pub trait AsMut<T: ?Sized> {
|
||||||
/// Performs the conversion.
|
/// Converts this type into a mutable reference of the (usually inferred) input type.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
fn as_mut(&mut self) -> &mut T;
|
fn as_mut(&mut self) -> &mut T;
|
||||||
}
|
}
|
||||||
|
@ -272,7 +272,7 @@ pub trait AsMut<T: ?Sized> {
|
||||||
#[rustc_diagnostic_item = "Into"]
|
#[rustc_diagnostic_item = "Into"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub trait Into<T>: Sized {
|
pub trait Into<T>: Sized {
|
||||||
/// Performs the conversion.
|
/// Converts this type into the (usually inferred) input type.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
fn into(self) -> T;
|
fn into(self) -> T;
|
||||||
|
@ -367,7 +367,7 @@ pub trait Into<T>: Sized {
|
||||||
note = "to coerce a `{T}` into a `{Self}`, use `&*` as a prefix",
|
note = "to coerce a `{T}` into a `{Self}`, use `&*` as a prefix",
|
||||||
))]
|
))]
|
||||||
pub trait From<T>: Sized {
|
pub trait From<T>: Sized {
|
||||||
/// Performs the conversion.
|
/// Converts to this type from the input type.
|
||||||
#[lang = "from"]
|
#[lang = "from"]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue