Skip to content

Commit

Permalink
Make InlineVec::from_buf unsafe (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
hwjsnc committed Sep 7, 2023
1 parent 263aa80 commit dbfe096
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ pub(crate) struct InlineVec {
impl InlineVec {
#[inline]
pub const fn new() -> Self {
Self::from_buf([0; LIMIT], 0)
// Safety: Trivially, 0 <= LIMIT
unsafe { Self::from_buf([0; LIMIT], 0) }
}

#[inline]
Expand All @@ -264,11 +265,14 @@ impl InlineVec {
i += 1;
}

Ok(Self::from_buf(buf, len))
// Safety: If len > LIMIT, Err was returned earlier.
unsafe { Ok(Self::from_buf(buf, len)) }
}

/// The given length may not exceed LIMIT.
#[inline]
pub const fn from_buf(buf: [u8; LIMIT], len: usize) -> Self {
pub const unsafe fn from_buf(buf: [u8; LIMIT], len: usize) -> Self {
debug_assert!(len <= LIMIT);
Self { buf, tagged_len: len as u8 | LEN_TAG }
}

Expand Down

0 comments on commit dbfe096

Please sign in to comment.