pub enum GetIntoBufferResult {
NotFound,
Found(usize),
BufferTooSmall(usize),
}Expand description
Result of a get_into_buffer operation.
This enum represents the outcome of attempting to read a value directly into a caller-provided buffer, avoiding memory allocation. This is the most efficient way to read values when you have a pre-allocated buffer available.
§Performance
Using get_into_buffer with a reusable buffer can significantly reduce
allocation overhead in hot paths compared to get or even
get_pinned:
get: Allocates a newVec<u8>for each callget_pinned: Pins memory in RocksDB’s block cacheget_into_buffer: Zero allocation when buffer is large enough
§Example
use rust_rocksdb::{DB, GetIntoBufferResult};
let db = DB::open_default(tempdir.path()).unwrap();
db.put(b"key", b"value").unwrap();
let mut buffer = [0u8; 1024];
match db.get_into_buffer(b"key", &mut buffer).unwrap() {
GetIntoBufferResult::Found(len) => {
println!("Value: {:?}", &buffer[..len]);
}
GetIntoBufferResult::NotFound => {
println!("Key not found");
}
GetIntoBufferResult::BufferTooSmall(needed) => {
println!("Need a buffer of at least {} bytes", needed);
}
}Variants§
NotFound
The key was not found in the database.
Found(usize)
The value was found and successfully copied into the buffer.
The usize contains the actual size of the value (number of bytes written).
BufferTooSmall(usize)
The value was found but the provided buffer was too small to hold it.
The usize contains the actual size of the value, allowing the caller
to allocate a larger buffer and retry.
Note: When this variant is returned, no data is written to the buffer.
Implementations§
Source§impl GetIntoBufferResult
impl GetIntoBufferResult
Sourcepub fn is_not_found(&self) -> bool
pub fn is_not_found(&self) -> bool
Returns true if the key was not found.
Sourcepub fn value_size(&self) -> Option<usize>
pub fn value_size(&self) -> Option<usize>
Returns the value size if the key was found, None otherwise.
Trait Implementations§
Source§impl Clone for GetIntoBufferResult
impl Clone for GetIntoBufferResult
Source§fn clone(&self) -> GetIntoBufferResult
fn clone(&self) -> GetIntoBufferResult
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more