Skip to content

Commit d29941e

Browse files
committed
Remove needless allocation from example code of OsString
1 parent 1f62c24 commit d29941e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

library/std/src/ffi/os_str.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,14 @@ impl OsString {
281281
///
282282
/// ```
283283
/// #![feature(try_reserve_2)]
284-
/// use std::ffi::OsString;
284+
/// use std::ffi::{OsStr, OsString};
285285
/// use std::collections::TryReserveError;
286286
///
287287
/// fn process_data(data: &str) -> Result<OsString, TryReserveError> {
288288
/// let mut s = OsString::new();
289289
///
290290
/// // Pre-reserve the memory, exiting if we can't
291-
/// s.try_reserve(OsString::from(data).len())?;
291+
/// s.try_reserve(OsStr::new(data).len())?;
292292
///
293293
/// // Now we know this can't OOM in the middle of our complex work
294294
/// s.push(data);
@@ -349,14 +349,14 @@ impl OsString {
349349
///
350350
/// ```
351351
/// #![feature(try_reserve_2)]
352-
/// use std::ffi::OsString;
352+
/// use std::ffi::{OsStr, OsString};
353353
/// use std::collections::TryReserveError;
354354
///
355355
/// fn process_data(data: &str) -> Result<OsString, TryReserveError> {
356356
/// let mut s = OsString::new();
357357
///
358358
/// // Pre-reserve the memory, exiting if we can't
359-
/// s.try_reserve_exact(OsString::from(data).len())?;
359+
/// s.try_reserve_exact(OsStr::new(data).len())?;
360360
///
361361
/// // Now we know this can't OOM in the middle of our complex work
362362
/// s.push(data);

0 commit comments

Comments
 (0)