about summary refs log tree commit diff
path: root/library/std/src/ffi/os_str.rs
diff options
context:
space:
mode:
authorbinarycat <binarycat@envs.net>2024-11-20 15:10:15 -0600
committerbinarycat <binarycat@envs.net>2024-11-20 15:16:05 -0600
commit7e79f913903a5c9f82e3f2e8afffa535159fcf54 (patch)
tree8841d40b425ff9ba6ebf230e42461e40adbaa738 /library/std/src/ffi/os_str.rs
parentbfe809d93c67de03e3a84b80549927fd828ec5d0 (diff)
downloadrust-7e79f913903a5c9f82e3f2e8afffa535159fcf54.tar.gz
rust-7e79f913903a5c9f82e3f2e8afffa535159fcf54.zip
implement OsString::truncate
Diffstat (limited to 'library/std/src/ffi/os_str.rs')
-rw-r--r--library/std/src/ffi/os_str.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs
index 79dfb47d0c4..328185d1f2b 100644
--- a/library/std/src/ffi/os_str.rs
+++ b/library/std/src/ffi/os_str.rs
@@ -550,11 +550,15 @@ impl OsString {
         OsStr::from_inner_mut(self.inner.leak())
     }
 
-    /// Provides plumbing to core `Vec::truncate`.
-    /// More well behaving alternative to allowing outer types
-    /// full mutable access to the core `Vec`.
+    /// Truncate the the `OsString` to the specified length.
+    ///
+    /// # Panics
+    /// Panics if `len` does not lie on a valid `OsStr` boundary
+    /// (as described in [`OsStr::slice_encoded_bytes`]).
     #[inline]
-    pub(crate) fn truncate(&mut self, len: usize) {
+    #[unstable(feature = "os_string_truncate", issue = "133262")]
+    pub fn truncate(&mut self, len: usize) {
+        self.as_os_str().inner.check_public_boundary(len);
         self.inner.truncate(len);
     }