diff options
| author | Mason Reed <mason@vector35.com> | 2025-07-13 17:34:02 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-07-15 12:34:43 -0400 |
| commit | bd1b6b8a1a75df296da5c7afa8107ba301c9cd8e (patch) | |
| tree | b0155db15147c9d91da10519ee72eb87560ba2d4 /rust/src/data_buffer.rs | |
| parent | fa3c81fd9b4287792c3e3d534a7d237d6005cb5f (diff) | |
[Rust] Add `BinaryView::search` and friends
Diffstat (limited to 'rust/src/data_buffer.rs')
| -rw-r--r-- | rust/src/data_buffer.rs | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/rust/src/data_buffer.rs b/rust/src/data_buffer.rs index a3f51d54..5f59393e 100644 --- a/rust/src/data_buffer.rs +++ b/rust/src/data_buffer.rs @@ -32,6 +32,12 @@ impl DataBuffer { self.0 } + pub fn new(data: &[u8]) -> Self { + let buffer = unsafe { BNCreateDataBuffer(data.as_ptr() as *const c_void, data.len()) }; + assert!(!buffer.is_null()); + DataBuffer::from_raw(buffer) + } + pub fn get_data(&self) -> &[u8] { let buffer = unsafe { BNGetDataBufferContents(self.0) }; if buffer.is_null() { @@ -161,15 +167,6 @@ impl DataBuffer { pub fn is_empty(&self) -> bool { self.len() == 0 } - - pub fn new(data: &[u8]) -> Result<Self, ()> { - let buffer = unsafe { BNCreateDataBuffer(data.as_ptr() as *const c_void, data.len()) }; - if buffer.is_null() { - Err(()) - } else { - Ok(DataBuffer::from_raw(buffer)) - } - } } impl Default for DataBuffer { @@ -192,10 +189,8 @@ impl Clone for DataBuffer { } } -impl TryFrom<&[u8]> for DataBuffer { - type Error = (); - - fn try_from(value: &[u8]) -> Result<Self, Self::Error> { +impl From<&[u8]> for DataBuffer { + fn from(value: &[u8]) -> Self { DataBuffer::new(value) } } |
