diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-10-05 23:03:02 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-10-05 23:03:02 -0700 |
| commit | 1651f1f4b8f97a51f1699101cfe03ea129ec7a07 (patch) | |
| tree | a8d513690b20f9a287652ea765a02b29d919a82b | |
| parent | 44f92c1f805434866b9744a6c8953ecdd8cc36f9 (diff) | |
| download | rust-1651f1f4b8f97a51f1699101cfe03ea129ec7a07.tar.gz rust-1651f1f4b8f97a51f1699101cfe03ea129ec7a07.zip | |
Elaborate some caveats to lossless
| -rw-r--r-- | library/core/src/convert/mod.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index aed5552ef91..c4b867a4809 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -484,7 +484,7 @@ pub trait Into<T>: Sized { /// a `From` implementation, the general expectation is that the conversions /// should typically be restricted as follows: /// -/// * The conversion is *infallible*: if the conversion can fail, use `TryFrom` +/// * The conversion is *infallible*: if the conversion can fail, use [`TryFrom`] /// instead; don't provide a `From` impl that panics. /// /// * The conversion is *lossless*: semantically, it should not lose or discard @@ -492,7 +492,10 @@ pub trait Into<T>: Sized { /// value can be recovered using `u16: TryFrom<i32>`. And `String: From<&str>` /// exists, where you can get something equivalent to the original value via /// `Deref`. But `From` cannot be used to convert from `u32` to `u16`, since -/// that cannot succeed in a lossless way. +/// that cannot succeed in a lossless way. (There's some wiggle room here for +/// information not considered semantically relevant. For example, +/// `Box<[T]>: From<Vec<T>>` exists even though it might not preserve capacity, +/// like how two vectors can be equal despite differing capacities.) /// /// * The conversion is *value-preserving*: the conceptual kind and meaning of /// the resulting value is the same, even though the Rust type and technical |
