@@ -45,6 +45,22 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
45
45
/// values, encoded in a less-strict variant of UTF-8. This is useful to
46
46
/// understand when handling capacity and length values.
47
47
///
48
+ /// # Capacity of `OsString`
49
+ ///
50
+ /// Capacity uses units of UTF-8 bytes for OS strings which were created from valid unicode, and
51
+ /// uses units of bytes in an unspecified encoding for other contents. On a given target, all
52
+ /// `OsString` and `OsStr` values use the same units for capacity, so the following will work:
53
+ /// ```
54
+ /// use std::ffi::{OsStr, OsString};
55
+ ///
56
+ /// fn concat_os_strings(a: &OsStr, b: &OsStr) -> OsString {
57
+ /// let mut ret = OsString::with_capacity(a.len() + b.len()); // This will allocate
58
+ /// ret.push(a); // This will not allocate further
59
+ /// ret.push(b); // This will not allocate further
60
+ /// ret
61
+ /// }
62
+ /// ```
63
+ ///
48
64
/// # Creating an `OsString`
49
65
///
50
66
/// **From a Rust string**: `OsString` implements
@@ -186,7 +202,7 @@ impl OsString {
186
202
/// OS strings without reallocating. If `capacity` is 0, the string will not
187
203
/// allocate.
188
204
///
189
- /// See main `OsString` documentation information about encoding.
205
+ /// See the main `OsString` documentation information about encoding and capacity units .
190
206
///
191
207
/// # Examples
192
208
///
@@ -229,7 +245,7 @@ impl OsString {
229
245
230
246
/// Returns the capacity this `OsString` can hold without reallocating.
231
247
///
232
- /// See `OsString` introduction for information about encoding.
248
+ /// See the main `OsString` documentation information about encoding and capacity units .
233
249
///
234
250
/// # Examples
235
251
///
@@ -251,6 +267,8 @@ impl OsString {
251
267
///
252
268
/// The collection may reserve more space to avoid frequent reallocations.
253
269
///
270
+ /// See the main `OsString` documentation information about encoding and capacity units.
271
+ ///
254
272
/// # Examples
255
273
///
256
274
/// ```
@@ -272,6 +290,8 @@ impl OsString {
272
290
/// greater than or equal to `self.len() + additional`. Does nothing if
273
291
/// capacity is already sufficient.
274
292
///
293
+ /// See the main `OsString` documentation information about encoding and capacity units.
294
+ ///
275
295
/// # Errors
276
296
///
277
297
/// If the capacity overflows, or the allocator reports a failure, then an error
@@ -313,6 +333,8 @@ impl OsString {
313
333
///
314
334
/// [`reserve`]: OsString::reserve
315
335
///
336
+ /// See the main `OsString` documentation information about encoding and capacity units.
337
+ ///
316
338
/// # Examples
317
339
///
318
340
/// ```
@@ -340,6 +362,8 @@ impl OsString {
340
362
///
341
363
/// [`try_reserve`]: OsString::try_reserve
342
364
///
365
+ /// See the main `OsString` documentation information about encoding and capacity units.
366
+ ///
343
367
/// # Errors
344
368
///
345
369
/// If the capacity overflows, or the allocator reports a failure, then an error
@@ -373,6 +397,8 @@ impl OsString {
373
397
374
398
/// Shrinks the capacity of the `OsString` to match its length.
375
399
///
400
+ /// See the main `OsString` documentation information about encoding and capacity units.
401
+ ///
376
402
/// # Examples
377
403
///
378
404
/// ```
@@ -399,6 +425,8 @@ impl OsString {
399
425
///
400
426
/// If the current capacity is less than the lower limit, this is a no-op.
401
427
///
428
+ /// See the main `OsString` documentation information about encoding and capacity units.
429
+ ///
402
430
/// # Examples
403
431
///
404
432
/// ```
@@ -773,6 +801,8 @@ impl OsStr {
773
801
/// This number is simply useful for passing to other methods, like
774
802
/// [`OsString::with_capacity`] to avoid reallocations.
775
803
///
804
+ /// See the main `OsString` documentation information about encoding and capacity units.
805
+ ///
776
806
/// # Examples
777
807
///
778
808
/// ```
0 commit comments