Skip to content

Commit

Permalink
Add unsafe push_bytes method to text::Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinecordelle committed Aug 25, 2023
1 parent 9c3e96c commit afdfbeb
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions capnp/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ impl<'a> Builder<'a> {
self.pos += bytes.len();
}

// SAFETY: the caller must guarantee that the bytes `bytes` are valid UTF-8.
pub unsafe fn push_bytes(&mut self, bytes: &[u8]) {
self.bytes[self.pos..(self.pos + bytes.len())].copy_from_slice(bytes);
self.pos += bytes.len();
}

pub fn clear(&mut self) {
for b in &mut self.bytes[..self.pos] {
*b = 0;
Expand Down

0 comments on commit afdfbeb

Please sign in to comment.