Remove needless allocation from example code of OsString

This commit is contained in:
David Tolnay 2021-12-30 12:45:02 -08:00
parent 1f62c24d5a
commit d29941e724
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82

View file

@ -281,14 +281,14 @@ impl OsString {
///
/// ```
/// #![feature(try_reserve_2)]
/// use std::ffi::OsString;
/// use std::ffi::{OsStr, OsString};
/// use std::collections::TryReserveError;
///
/// fn process_data(data: &str) -> Result<OsString, TryReserveError> {
/// let mut s = OsString::new();
///
/// // Pre-reserve the memory, exiting if we can't
/// s.try_reserve(OsString::from(data).len())?;
/// s.try_reserve(OsStr::new(data).len())?;
///
/// // Now we know this can't OOM in the middle of our complex work
/// s.push(data);
@ -349,14 +349,14 @@ impl OsString {
///
/// ```
/// #![feature(try_reserve_2)]
/// use std::ffi::OsString;
/// use std::ffi::{OsStr, OsString};
/// use std::collections::TryReserveError;
///
/// fn process_data(data: &str) -> Result<OsString, TryReserveError> {
/// let mut s = OsString::new();
///
/// // Pre-reserve the memory, exiting if we can't
/// s.try_reserve_exact(OsString::from(data).len())?;
/// s.try_reserve_exact(OsStr::new(data).len())?;
///
/// // Now we know this can't OOM in the middle of our complex work
/// s.push(data);