Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions crates/oxc_data_structures/src/inline_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ impl<const CAPACITY: usize, Len: UnsignedInt> InlineString<CAPACITY, Len> {
std::str::from_utf8_unchecked(slice)
}
}

/// Get string as `&mut str` slice.
#[inline]
pub fn as_mut_str(&mut self) -> &mut str {
// SAFETY: If safety conditions of `push_unchecked` have been upheld,
// `self.len <= CAPACITY`, and contents of slice of `bytes` is a valid UTF-8 string
unsafe {
assert_unchecked!(self.len.to_usize() <= CAPACITY);
let slice = &mut self.bytes[..self.len.to_usize()];
std::str::from_utf8_unchecked_mut(slice)
}
}
}

impl<const CAPACITY: usize, Len: UnsignedInt> Default for InlineString<CAPACITY, Len> {
Expand Down
Loading