Skip to content

Commit 2877a01

Browse files
committed
Address review comments
1 parent d35fa1e commit 2877a01

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

src/libcore/convert.rs

+19-24
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
//! - [`From`]`<U> for T` implies [`Into`]`<T> for U`
3636
//! - [`TryFrom`]`<U> for T` implies [`TryInto`]`<T> for U`
3737
//! - [`From`] and [`Into`] are reflexive, which means that all types can
38-
//! `into()` themselves and `from()` themselves
38+
//! `into` themselves and `from` themselves
3939
//!
4040
//! See each trait for usage examples.
4141
//!
@@ -59,14 +59,15 @@ use str::FromStr;
5959
/// `AsRef` is to be used when wishing to convert to a reference of another
6060
/// type.
6161
/// `Borrow` is more related to the notion of taking the reference. It is
62-
/// useful when wishing to abstract
63-
/// over the type of reference (`&T`, `&mut T`) or allow both the referenced
64-
/// and owned type to be treated in the same manner.
62+
/// useful when wishing to abstract over the type of reference
63+
/// (`&T`, `&mut T`) or allow both the referenced and owned type to be treated
64+
/// in the same manner.
65+
///
6566
/// The key difference between the two traits is the intention:
6667
///
6768
/// - Use `AsRef` when goal is to simply convert into a reference
6869
/// - Use `Borrow` when goal is related to writing code that is agnostic to the
69-
/// type of borrow and if is reference or value
70+
/// type of borrow and if is reference or value
7071
///
7172
/// See [the book][book] for a more detailed comparison.
7273
///
@@ -82,8 +83,8 @@ use str::FromStr;
8283
/// # Generic Implementations
8384
///
8485
/// - `AsRef` auto-dereferences if the inner type is a reference or a mutable
85-
/// reference (e.g.: `foo.as_ref()` will work the same if `foo` has type
86-
/// `&mut Foo` or `&&mut Foo`)
86+
/// reference (e.g.: `foo.as_ref()` will work the same if `foo` has type
87+
/// `&mut Foo` or `&&mut Foo`)
8788
///
8889
/// # Examples
8990
///
@@ -124,8 +125,8 @@ pub trait AsRef<T: ?Sized> {
124125
/// # Generic Implementations
125126
///
126127
/// - `AsMut` auto-dereferences if the inner type is a reference or a mutable
127-
/// reference (e.g.: `foo.as_ref()` will work the same if `foo` has type
128-
/// `&mut Foo` or `&&mut Foo`)
128+
/// reference (e.g.: `foo.as_ref()` will work the same if `foo` has type
129+
/// `&mut Foo` or `&&mut Foo`)
129130
///
130131
/// # Examples
131132
///
@@ -203,9 +204,11 @@ pub trait Into<T>: Sized {
203204
///
204205
/// When constructing a function that is capable of failing the return type
205206
/// will generally be of the form `Result<T, E>`.
207+
///
206208
/// The `From` trait allows for simplification of error handling by providing a
207209
/// means of returning a single error type that encapsulates numerous possible
208210
/// erroneous situations.
211+
///
209212
/// This trait is not limited to error handling, rather the general case for
210213
/// this trait would be in any type conversions to have an explicit definition
211214
/// of how they are performed.
@@ -310,8 +313,7 @@ pub trait TryFrom<T>: Sized {
310313

311314
// As lifts over &
312315
#[stable(feature = "rust1", since = "1.0.0")]
313-
impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a T
314-
where T: AsRef<U>
316+
impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a T where T: AsRef<U>
315317
{
316318
fn as_ref(&self) -> &U {
317319
<T as AsRef<U>>::as_ref(*self)
@@ -320,8 +322,7 @@ impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a T
320322

321323
// As lifts over &mut
322324
#[stable(feature = "rust1", since = "1.0.0")]
323-
impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a mut T
324-
where T: AsRef<U>
325+
impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a mut T where T: AsRef<U>
325326
{
326327
fn as_ref(&self) -> &U {
327328
<T as AsRef<U>>::as_ref(*self)
@@ -338,8 +339,7 @@ impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a mut T
338339

339340
// AsMut lifts over &mut
340341
#[stable(feature = "rust1", since = "1.0.0")]
341-
impl<'a, T: ?Sized, U: ?Sized> AsMut<U> for &'a mut T
342-
where T: AsMut<U>
342+
impl<'a, T: ?Sized, U: ?Sized> AsMut<U> for &'a mut T where T: AsMut<U>
343343
{
344344
fn as_mut(&mut self) -> &mut U {
345345
(*self).as_mut()
@@ -356,8 +356,7 @@ impl<'a, T: ?Sized, U: ?Sized> AsMut<U> for &'a mut T
356356

357357
// From implies Into
358358
#[stable(feature = "rust1", since = "1.0.0")]
359-
impl<T, U> Into<U> for T
360-
where U: From<T>
359+
impl<T, U> Into<U> for T where U: From<T>
361360
{
362361
fn into(self) -> U {
363362
U::from(self)
@@ -367,16 +366,13 @@ impl<T, U> Into<U> for T
367366
// From (and thus Into) is reflexive
368367
#[stable(feature = "rust1", since = "1.0.0")]
369368
impl<T> From<T> for T {
370-
fn from(t: T) -> T {
371-
t
372-
}
369+
fn from(t: T) -> T { t }
373370
}
374371

375372

376373
// TryFrom implies TryInto
377374
#[unstable(feature = "try_from", issue = "33417")]
378-
impl<T, U> TryInto<U> for T
379-
where U: TryFrom<T>
375+
impl<T, U> TryInto<U> for T where U: TryFrom<T>
380376
{
381377
type Error = U::Error;
382378

@@ -413,8 +409,7 @@ impl AsRef<str> for str {
413409

414410
// FromStr implies TryFrom<&str>
415411
#[unstable(feature = "try_from", issue = "33417")]
416-
impl<'a, T> TryFrom<&'a str> for T
417-
where T: FromStr
412+
impl<'a, T> TryFrom<&'a str> for T where T: FromStr
418413
{
419414
type Error = <T as FromStr>::Err;
420415

0 commit comments

Comments
 (0)