diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-02-17 06:29:57 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-17 06:29:57 +0100 |
| commit | 1cc0ae4cbbcb9909035b5b99fc20bf6b79f4010c (patch) | |
| tree | 5a6133d1341637821d26a31af27b8923e244e134 /library/alloc/src | |
| parent | 930fc4f59ddeb9f26d554a2c75c5355989189540 (diff) | |
| parent | 6fd5cf51c1528c16f8a186ced5d6d21b1d70e319 (diff) | |
| download | rust-1cc0ae4cbbcb9909035b5b99fc20bf6b79f4010c.tar.gz rust-1cc0ae4cbbcb9909035b5b99fc20bf6b79f4010c.zip | |
Rollup merge of #89869 - kpreid:from-doc, r=yaahc
Add documentation to more `From::from` implementations. For users looking at documentation through IDE popups, this gives them relevant information rather than the generic trait documentation wording “Performs the conversion”. For users reading the documentation for a specific type for any reason, this informs them when the conversion may allocate or copy significant memory versus when it is always a move or cheap copy. Notes on specific cases: * The new documentation for `From<T> for T` explains that it is not a conversion at all. * Also documented `impl<T, U> Into<U> for T where U: From<T>`, the other central blanket implementation of conversion. * The new documentation for construction of maps and sets from arrays of keys mentions the handling of duplicates. Future work could be to do this for *all* code paths that convert an iterable to a map or set. * I did not add documentation to conversions of a specific error type to a more general error type. * I did not add documentation to unstable code. This change was prepared by searching for the text "From<... for" and so may have missed some cases that for whatever reason did not match. I also looked for `Into` impls but did not find any worth documenting by the above criteria.
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/collections/btree/map.rs | 2 | ||||
| -rw-r--r-- | library/alloc/src/collections/btree/set.rs | 2 | ||||
| -rw-r--r-- | library/alloc/src/collections/linked_list.rs | 2 | ||||
| -rw-r--r-- | library/alloc/src/collections/vec_deque/mod.rs | 2 | ||||
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 9 |
5 files changed, 13 insertions, 4 deletions
diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index cdb961d4cfb..67f5b386ecd 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -2052,6 +2052,8 @@ where #[stable(feature = "std_collections_from_array", since = "1.56.0")] impl<K: Ord, V, const N: usize> From<[(K, V); N]> for BTreeMap<K, V> { + /// Converts a `[(K, V); N]` into a `BTreeMap<(K, V)>`. + /// /// ``` /// use std::collections::BTreeMap; /// diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs index 31df4e98ed7..a4315be74e3 100644 --- a/library/alloc/src/collections/btree/set.rs +++ b/library/alloc/src/collections/btree/set.rs @@ -1097,6 +1097,8 @@ impl<T: Ord> FromIterator<T> for BTreeSet<T> { #[stable(feature = "std_collections_from_array", since = "1.56.0")] impl<T: Ord, const N: usize> From<[T; N]> for BTreeSet<T> { + /// Converts a `[T; N]` into a `BTreeSet<T>`. + /// /// ``` /// use std::collections::BTreeSet; /// diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index 4a07d5d4bed..d81f24e7202 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -1953,6 +1953,8 @@ impl<T: Hash> Hash for LinkedList<T> { #[stable(feature = "std_collections_from_array", since = "1.56.0")] impl<T, const N: usize> From<[T; N]> for LinkedList<T> { + /// Converts a `[T; N]` into a `LinkedList<T>`. + /// /// ``` /// use std::collections::LinkedList; /// diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index db2ad5e8d28..763175fc045 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -3049,6 +3049,8 @@ impl<T, A: Allocator> From<VecDeque<T, A>> for Vec<T, A> { #[stable(feature = "std_collections_from_array", since = "1.56.0")] impl<T, const N: usize> From<[T; N]> for VecDeque<T> { + /// Converts a `[T; N]` into a `VecDeque<T>`. + /// /// ``` /// use std::collections::VecDeque; /// diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index bd3262b51d4..3dc3eee4133 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2906,10 +2906,6 @@ impl<T: Clone> From<&mut [T]> for Vec<T> { #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_from_array", since = "1.44.0")] impl<T, const N: usize> From<[T; N]> for Vec<T> { - #[cfg(not(test))] - fn from(s: [T; N]) -> Vec<T> { - <[T]>::into_vec(box s) - } /// Allocate a `Vec<T>` and move `s`'s items into it. /// /// # Examples @@ -2917,6 +2913,11 @@ impl<T, const N: usize> From<[T; N]> for Vec<T> { /// ``` /// assert_eq!(Vec::from([1, 2, 3]), vec![1, 2, 3]); /// ``` + #[cfg(not(test))] + fn from(s: [T; N]) -> Vec<T> { + <[T]>::into_vec(box s) + } + #[cfg(test)] fn from(s: [T; N]) -> Vec<T> { crate::slice::into_vec(box s) |
