Skip to content

Commit

Permalink
allow &str to be pushable
Browse files Browse the repository at this point in the history
  • Loading branch information
weikengchen committed Jul 22, 2024
1 parent e5ce338 commit ebce783
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ pub fn define_pushable(_: TokenStream) -> TokenStream {
impl NotU8Pushable for usize {
fn bitcoin_script_push(&self, builder: Builder) -> Builder {
builder.push_int(
i64::try_from(*self).unwrap_or_else(|_| panic!("Usize does not fit in i64")),
i64::try_from(*self)
.unwrap_or_else(|_| panic!("Usize does not fit in i64")),
)
}
}
Expand Down Expand Up @@ -246,6 +247,11 @@ pub fn define_pushable(_: TokenStream) -> TokenStream {
Builder::from(script_vec)
}
}
impl NotU8Pushable for &str {
fn bitcoin_script_push(&self, builder: Builder) -> Builder {
builder.push_slice(PushBytesBuf::try_from(self.as_bytes().to_vec()).unwrap())
}
}
impl<T: NotU8Pushable> NotU8Pushable for Vec<T> {
fn bitcoin_script_push(&self, mut builder: Builder) -> Builder {
for pushable in self.iter() {
Expand Down

0 comments on commit ebce783

Please sign in to comment.