Skip to content

Commit 1651f1f

Browse files
committed
Elaborate some caveats to lossless
1 parent 44f92c1 commit 1651f1f

File tree

1 file changed

+5
-2
lines changed
  • library/core/src/convert

1 file changed

+5
-2
lines changed

Diff for: library/core/src/convert/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -484,15 +484,18 @@ pub trait Into<T>: Sized {
484484
/// a `From` implementation, the general expectation is that the conversions
485485
/// should typically be restricted as follows:
486486
///
487-
/// * The conversion is *infallible*: if the conversion can fail, use `TryFrom`
487+
/// * The conversion is *infallible*: if the conversion can fail, use [`TryFrom`]
488488
/// instead; don't provide a `From` impl that panics.
489489
///
490490
/// * The conversion is *lossless*: semantically, it should not lose or discard
491491
/// information. For example, `i32: From<u16>` exists, where the original
492492
/// value can be recovered using `u16: TryFrom<i32>`. And `String: From<&str>`
493493
/// exists, where you can get something equivalent to the original value via
494494
/// `Deref`. But `From` cannot be used to convert from `u32` to `u16`, since
495-
/// that cannot succeed in a lossless way.
495+
/// that cannot succeed in a lossless way. (There's some wiggle room here for
496+
/// information not considered semantically relevant. For example,
497+
/// `Box<[T]>: From<Vec<T>>` exists even though it might not preserve capacity,
498+
/// like how two vectors can be equal despite differing capacities.)
496499
///
497500
/// * The conversion is *value-preserving*: the conceptual kind and meaning of
498501
/// the resulting value is the same, even though the Rust type and technical

0 commit comments

Comments
 (0)