Skip to content

Commit

Permalink
feat: add capacity api for prealloc (#15)
Browse files Browse the repository at this point in the history
* feat: add api to get the capacity of prealloc

* fix: doc

---------

Co-authored-by: Breeze-P <noreply@greptime.com>
  • Loading branch information
Breeze-P and Breeze-P authored Nov 26, 2024
1 parent 4de657c commit 1e436b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/producer/prealloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ pub struct PreAlloc {
}

impl PreAlloc {
/// Get the slice of the pre-allocated.
/// Get the slice of the [`PreAlloc`].
pub fn slice(&self) -> &[u8] {
self.data_block.slice().unwrap()
}

/// Write data to the pre-allocated.
/// Get the capacity of the [`PreAlloc`].
pub fn capacity(&self) -> u32 {
self.data_block.capacity()
}

/// Write data to the [`PreAlloc`].
pub fn write(&mut self, data: &[u8]) -> Result<()> {
self.data_block.write(data)
}
Expand Down
2 changes: 1 addition & 1 deletion src/ringbuf/data_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl<T> DataBlock<T> {
self.capacity() + HEADER_LEN as u32
}

fn capacity(&self) -> u32 {
pub(crate) fn capacity(&self) -> u32 {
self.header.capacity()
}

Expand Down

0 comments on commit 1e436b8

Please sign in to comment.