From c0e913fdd7f35b197c6da198c25569fc63244b85 Mon Sep 17 00:00:00 2001 From: Noa Date: Fri, 8 Mar 2024 12:27:24 -0600 Subject: Document overrides of `clone_from()` Specifically, when an override doesn't just forward to an inner type, document the behavior and that it's preferred over simply assigning a clone of source. Also, change instances where the second parameter is "other" to "source". --- library/alloc/src/string.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'library/alloc/src/string.rs') diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index 98ded7f6cdf..fd36583ec8e 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -2084,6 +2084,10 @@ impl Clone for String { String { vec: self.vec.clone() } } + /// Clones the contents of `source` into `self`. + /// + /// This method is preferred over simply assigning `source.clone()` to `self`, + /// as it avoids reallocation if possible. fn clone_from(&mut self, source: &Self) { self.vec.clone_from(&source.vec); } -- cgit 1.4.1-3-g733a5