Skip to content

Commit

Permalink
Rollup merge of #133264 - lolbinarycat:os-string-truncate, r=joboet
Browse files Browse the repository at this point in the history
implement OsString::truncate

part of #133262
  • Loading branch information
compiler-errors authored Nov 23, 2024
2 parents 469a219 + 7e79f91 commit 7b3e593
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions library/std/src/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 7b3e593

Please sign in to comment.