Add `Builder::with_capacity()`

This commit is contained in:
Daniel Roberts 2025-04-06 21:06:17 -05:00
parent e492f94289
commit d003d48592
2 changed files with 11 additions and 0 deletions

View File

@ -21,6 +21,10 @@ impl Builder {
#[inline] #[inline]
pub const fn new() -> Self { Builder(ScriptBuf::new(), None) } pub const fn new() -> Self { Builder(ScriptBuf::new(), None) }
/// Constructs a new empty script builder with at least the specified capacity.
#[inline]
pub fn with_capacity(capacity: usize) -> Self { Builder(ScriptBuf::with_capacity(capacity), None) }
/// Returns the length in bytes of the script. /// Returns the length in bytes of the script.
pub fn len(&self) -> usize { self.0.len() } pub fn len(&self) -> usize { self.0.len() }

View File

@ -209,6 +209,13 @@ fn script_builder() {
); );
} }
#[test]
fn script_builder_with_capacity() {
let script = Builder::with_capacity(42);
assert!(script.into_script().capacity() >= 42);
}
#[test] #[test]
fn script_generators() { fn script_generators() {
let pubkey = "0234e6a79c5359c613762d537e0e19d86c77c1666d8c9ab050f23acd198e97f93e" let pubkey = "0234e6a79c5359c613762d537e0e19d86c77c1666d8c9ab050f23acd198e97f93e"