Skip to content

Commit

Permalink
feat: made more len and is_empty methods const
Browse files Browse the repository at this point in the history
  • Loading branch information
bluurryy committed Oct 14, 2024
1 parent a8ab946 commit 32f3bb3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- **added:** missing string methods to `BumpBox<str>`: `len`, `is_empty`, `set_len`, `retain`, `clear`, `as_ptr`, `as_mut_ptr`, `remove`, `as_mut_bytes`
- **added:** `Default` for `FixedBumpString`
- **added:** string methods `pop`, `truncate`
- **added:** made more `len` and `is_empty` methods `const`

## 0.10.1 (2024-10-14)
- **added:** `MutBumpVecRev::{ append, into_flattened, unchecked_push(_with), as_non_null_{ptr, slice} }`
Expand Down
6 changes: 3 additions & 3 deletions src/bump_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ where
/// length of the string.
#[must_use]
#[inline(always)]
pub fn len(&self) -> usize {
pub const fn len(&self) -> usize {
self.fixed.len()
}

/// Returns `true` if this `BumpString` has a length of zero, and `false` otherwise.
#[must_use]
#[inline(always)]
pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
self.fixed.is_empty()
}

Expand Down Expand Up @@ -703,7 +703,7 @@ where
}

unsafe fn insert_bytes<B: ErrorBehavior>(&mut self, idx: usize, bytes: &[u8]) -> Result<(), B> {
let vec = unsafe { self.as_mut_vec() };
let vec = self.as_mut_vec();

let len = vec.len();
let amt = bytes.len();
Expand Down
6 changes: 3 additions & 3 deletions src/fixed_bump_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ impl<'a> FixedBumpString<'a> {
/// length of the string.
#[must_use]
#[inline(always)]
pub fn len(&self) -> usize {
pub const fn len(&self) -> usize {
self.initialized.len()
}

/// Returns `true` if this `FixedBumpString` has a length of zero, and `false` otherwise.
#[must_use]
#[inline(always)]
pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
self.initialized.is_empty()
}

Expand Down Expand Up @@ -567,7 +567,7 @@ impl<'a> FixedBumpString<'a> {
}

unsafe fn insert_bytes<B: ErrorBehavior>(&mut self, idx: usize, bytes: &[u8]) -> Result<(), B> {
let vec = unsafe { self.as_mut_vec() };
let vec = self.as_mut_vec();

let len = vec.len();
let amt = bytes.len();
Expand Down
6 changes: 3 additions & 3 deletions src/mut_bump_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ impl<'b, 'a: 'b, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCA
/// length of the string.
#[must_use]
#[inline(always)]
pub fn len(&self) -> usize {
pub const fn len(&self) -> usize {
self.fixed.len()
}

/// Returns `true` if this `MutBumpString` has a length of zero, and `false` otherwise.
#[must_use]
#[inline(always)]
pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
self.fixed.is_empty()
}

Expand Down Expand Up @@ -702,7 +702,7 @@ where
}

unsafe fn insert_bytes<B: ErrorBehavior>(&mut self, idx: usize, bytes: &[u8]) -> Result<(), B> {
let vec = unsafe { self.as_mut_vec() };
let vec = self.as_mut_vec();

let len = vec.len();
let amt = bytes.len();
Expand Down

0 comments on commit 32f3bb3

Please sign in to comment.