about summary refs log tree commit diff
diff options
context:
space:
mode:
authorxizheyin <xizheyin@smail.nju.edu.cn>2025-05-08 18:12:05 +0800
committerxizheyin <xizheyin@smail.nju.edu.cn>2025-05-08 18:12:05 +0800
commit4101d90818b7e5574d5366e24c995980fa2de866 (patch)
treeafe49ae71a873349485c650a4ea06e5b42decd8b
parentb6c2a429efd85cbfa5f592c66faac6955729c6ea (diff)
downloadrust-4101d90818b7e5574d5366e24c995980fa2de866.tar.gz
rust-4101d90818b7e5574d5366e24c995980fa2de866.zip
std: Explain prefer `TryInto` over `TryFrom` when specifying traits bounds on generic function
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
-rw-r--r--library/core/src/convert/mod.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs
index ef184e1ceb4..c542a28beb8 100644
--- a/library/core/src/convert/mod.rs
+++ b/library/core/src/convert/mod.rs
@@ -597,6 +597,9 @@ pub trait From<T>: Sized {
 /// standard library. For more information on this, see the
 /// documentation for [`Into`].
 ///
+/// Prefer using [`TryInto`] over [`TryFrom`] when specifying trait bounds on a generic function
+/// to ensure that types that only implement [`TryInto`] can be used as well.
+///
 /// # Implementing `TryInto`
 ///
 /// This suffers the same restrictions and reasoning as implementing
@@ -636,6 +639,9 @@ pub trait TryInto<T>: Sized {
 /// When the [`!`] type is stabilized [`Infallible`] and [`!`] will be
 /// equivalent.
 ///
+/// Prefer using [`TryInto`] over [`TryFrom`] when specifying trait bounds on a generic function
+/// to ensure that types that only implement [`TryInto`] can be used as well.
+///
 /// `TryFrom<T>` can be implemented as follows:
 ///
 /// ```