Add comment to append_string for Standard
This commit is contained in:
@@ -94,6 +94,9 @@ impl Distribution<char> for Standard {
|
||||
#[cfg(feature = "alloc")]
|
||||
impl DistString for Standard {
|
||||
fn append_string<R: Rng + ?Sized>(&self, rng: &mut R, s: &mut String, len: usize) {
|
||||
// A char is encoded with at most four bytes, thus this reservation is
|
||||
// guaranteed to be sufficient. We do not shrink_to_fit afterwards so
|
||||
// that repeated usage on the same `String` buffer does not reallocate.
|
||||
s.reserve(s.len() + 4 * len);
|
||||
s.extend(Distribution::<char>::sample_iter(self, rng).take(len));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user