Skip to content

Commit f9aaad0

Browse files
committed
docs: Add examples of OsStr safety violation
1 parent 7b92903 commit f9aaad0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

library/std/src/ffi/os_str.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,10 @@ impl OsStr {
678678
/// `OsStr`'s encoding is an unspecified superset of UTF-8 and callers must
679679
/// pass in bytes that originated as a mixture of validated UTF-8 and bytes from
680680
/// [`OsStr::as_os_str_bytes`] from within the same rust version built for the same target
681-
/// platform. The bytes from `OsStr::as_os_str_bytes` may be split either
682-
/// immediately before or immediately after some valid non-empty UTF-8 substring
681+
/// platform. For example, reconstructing an `OsStr` from bytes sent over the network or stored
682+
/// in a file will likely violate these safety rules. The bytes from `OsStr::as_os_str_bytes`
683+
/// may be split either immediately before or immediately after some valid non-empty UTF-8
684+
/// substring
683685
///
684686
/// # Example
685687
///
@@ -881,8 +883,9 @@ impl OsStr {
881883
///
882884
/// Note: As the encoding is unspecified, any sub-slice of bytes that is not valid UTF-8 should
883885
/// be treated as opaque and only comparable within the same rust version built for the same
884-
/// target platform. See [`OsString`] for more encoding details and [`std::ffi`] for
885-
/// platform-specific, specified conversions.
886+
/// target platform. For example, sending the slice over the network or storing it in a file
887+
/// will likely result in incompatible byte slices See [`OsString`] for more encoding details
888+
/// and [`std::ffi`] for platform-specific, specified conversions.
886889
///
887890
/// [`std::ffi`]: crate::ffi
888891
#[inline]

0 commit comments

Comments
 (0)