Skip to content

Commit 4101d90

Browse files
committed
std: Explain prefer TryInto over TryFrom when specifying traits bounds on generic function
Signed-off-by: xizheyin <[email protected]>
1 parent b6c2a42 commit 4101d90

File tree

1 file changed

+6
-0
lines changed
  • library/core/src/convert

1 file changed

+6
-0
lines changed

library/core/src/convert/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,9 @@ pub trait From<T>: Sized {
597597
/// standard library. For more information on this, see the
598598
/// documentation for [`Into`].
599599
///
600+
/// Prefer using [`TryInto`] over [`TryFrom`] when specifying trait bounds on a generic function
601+
/// to ensure that types that only implement [`TryInto`] can be used as well.
602+
///
600603
/// # Implementing `TryInto`
601604
///
602605
/// This suffers the same restrictions and reasoning as implementing
@@ -636,6 +639,9 @@ pub trait TryInto<T>: Sized {
636639
/// When the [`!`] type is stabilized [`Infallible`] and [`!`] will be
637640
/// equivalent.
638641
///
642+
/// Prefer using [`TryInto`] over [`TryFrom`] when specifying trait bounds on a generic function
643+
/// to ensure that types that only implement [`TryInto`] can be used as well.
644+
///
639645
/// `TryFrom<T>` can be implemented as follows:
640646
///
641647
/// ```

0 commit comments

Comments
 (0)