Make Witness a wrapper type.

This commit is contained in:
Alejandro Cabeza Romero 2026-05-14 14:40:46 +02:00
parent ca118adbfe
commit 713fae388c
No known key found for this signature in database
GPG Key ID: DA3D14AE478030FD
5 changed files with 18 additions and 6 deletions

View File

@ -77,6 +77,6 @@ mod tests {
witness_output_path.display()
)
});
assert_eq!(output.iter().as_slice(), expected.as_slice());
assert_eq!(output.as_ref().iter().as_slice(), expected.as_slice());
}
}

View File

@ -77,6 +77,6 @@ mod tests {
witness_output_path.display()
)
});
assert_eq!(output.iter().as_slice(), expected.as_slice());
assert_eq!(output.as_ref().iter().as_slice(), expected.as_slice());
}
}

View File

@ -77,6 +77,6 @@ mod tests {
witness_output_path.display()
)
});
assert_eq!(output.iter().as_slice(), expected.as_slice());
assert_eq!(output.as_ref().iter().as_slice(), expected.as_slice());
}
}

View File

@ -82,6 +82,6 @@ mod tests {
witness_output_path.display()
)
});
assert_eq!(output.iter().as_slice(), expected.as_slice());
assert_eq!(output.as_ref().iter().as_slice(), expected.as_slice());
}
}

View File

@ -4,7 +4,19 @@ use crate::ffi;
///
/// When constructing from [`From<ffi::Bytes>`], it takes ownership of the underlying value and
/// frees it.
pub type Witness = bytes::Bytes;
pub struct Witness(bytes::Bytes);
impl From<bytes::Bytes> for Witness {
fn from(bytes: bytes::Bytes) -> Self {
Self(bytes)
}
}
impl AsRef<bytes::Bytes> for Witness {
fn as_ref(&self) -> &bytes::Bytes {
&self.0
}
}
impl From<ffi::Bytes> for Witness {
fn from(mut ffi_value: ffi::Bytes) -> Self {
@ -17,6 +29,6 @@ impl From<ffi::Bytes> for Witness {
};
// SAFETY: `ffi_value` is a local variable, so the raw pointer is valid for this call.
unsafe { ffi::free_bytes(&raw mut ffi_value) };
Self::from(vec)
Self::from(bytes::Bytes::from(vec))
}
}