Skip to content

Commit 87d9b99

Browse files
committed
feat: push_str capacity exceeds error message
1 parent 4298478 commit 87d9b99

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/bounded_str.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,17 @@ impl<const N: usize, Alignment> BoundedStr<N, Alignment> {
159159
pub fn push_str(&mut self, s: &str) -> Result<(), ExceedsCapacity> {
160160
let bytes = s.as_bytes();
161161
let length = self.length as usize;
162+
let new_len = length + bytes.len();
162163

163-
if length + bytes.len() > N {
164+
if new_len > N {
164165
return Err(ExceedsCapacity {
165-
length,
166+
length: new_len,
166167
capacity: N,
167168
});
168169
}
169170

170-
self.data[length..length + bytes.len()].copy_from_slice(bytes);
171-
self.length += bytes.len() as u8;
171+
self.data[length..new_len].copy_from_slice(bytes);
172+
self.length = new_len as u8;
172173

173174
Ok(())
174175
}

0 commit comments

Comments
 (0)