Minor improvements.

This commit is contained in:
Alejandro Cabeza Romero 2026-04-24 12:12:40 +02:00
parent a291e1cb54
commit e4e495f9b2
No known key found for this signature in database
GPG Key ID: DA3D14AE478030FD
4 changed files with 13 additions and 6 deletions

View File

@ -2,6 +2,13 @@ use crate::ffi;
pub struct Bytes(Vec<u8>);
impl Bytes {
#[must_use]
pub fn inner(&self) -> &Vec<u8> {
&self.0
}
}
impl From<ffi::Bytes> for Bytes {
fn from(mut ffi_value: ffi::Bytes) -> Self {
let raw = unsafe {

View File

@ -34,7 +34,7 @@ impl TryFrom<crate::ffi::Status> for () {
let error_message = message
.map(|inner| DynError::from(inner.to_string_lossy().to_owned()))
.unwrap_or_else(|| DynError::from("Unknown error"));
Err(Error::Other(error_message))
Err(error_message.into())
},
FfiStatusCode::InvalidInput => Err(Error::InvalidInput),
FfiStatusCode::OutOfMemory => Err(Error::OutOfMemory),

View File

@ -18,9 +18,10 @@ impl WitnessInput {
}
}
/// Represents a guard for managing the lifetime of a WitnessInput in FFI.
/// This struct ensures that the memory allocated for the FFI representation of WitnessInput is
/// properly released when it goes out of scope.
/// Temporary FFI view of a [`WitnessInput`], valid for the lifetime of the source.
///
/// Owns the C string allocation of `WitnessInput::inputs_json` and ensures it is freed when
/// dropped.
pub struct WitnessInputFfiGuard<'a> {
ffi: ffi::WitnessInput,
_lifetime: std::marker::PhantomData<&'a WitnessInput>,
@ -28,7 +29,7 @@ pub struct WitnessInputFfiGuard<'a> {
impl<'a> WitnessInputFfiGuard<'a> {
#[must_use]
pub fn new(inner: &'a WitnessInput) -> Self {
fn new(inner: &'a WitnessInput) -> Self {
let dat = ffi::ConstBytes { data: inner.dat.as_ptr(), size: inner.dat.len() };
let inputs_json = CString::new(inner.inputs_json.clone()).expect("CString::new failed").into_raw();
let ffi = ffi::WitnessInput { dat, inputs_json };

View File

@ -1,4 +1,3 @@
use std::cmp::PartialEq;
use std::ffi::c_char;
#[repr(C)]