Skip to content

Commit 7ec2f77

Browse files
committed
chore: rustfmt, clippy
1 parent 84f4303 commit 7ec2f77

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

macro/src/generate.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use proc_macro2::{Ident, Span, TokenStream};
44
use quote::{quote, quote_spanned};
55

66
pub fn generate(syntax: Vec<(Syntax, Span)>) -> TokenStream {
7-
let mut tokens = quote!(::bitcoin_script::Script::new(::bitcoin_script::function_name!()));
7+
let mut tokens = quote!(::bitcoin_script::Script::new(
8+
::bitcoin_script::function_name!()
9+
));
810

911
for (item, span) in syntax {
1012
let push = match item {

macro/src/parse.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,7 @@ pub fn parse(tokens: TokenStream) -> Vec<(Syntax, Span)> {
355355
// Wrap if-else statements such that they return a Vec<ScriptBuf>
356356
(Ident(_), "if") => parse_if(token, &mut tokens),
357357
// Replace DEBUG with OP_RESERVED
358-
(Ident(_), "DEBUG") => {
359-
(Syntax::Opcode(OP_RESERVED), token.span())
360-
}
358+
(Ident(_), "DEBUG") => (Syntax::Opcode(OP_RESERVED), token.span()),
361359

362360
// identifier, look up opcode
363361
(Ident(_), _) => match parse_opcode(&token_str) {

src/builder.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,18 @@ fn calculate_hash<T: Hash>(t: &T) -> u64 {
4747

4848
impl StructuredScript {
4949
pub fn new(debug_info: &str) -> Self {
50-
let blocks = Vec::new();
5150
StructuredScript {
5251
size: 0,
5352
debug_identifier: debug_info.to_string(),
54-
blocks,
53+
blocks: Vec::new(),
5554
script_map: HashMap::new(),
5655
}
5756
}
5857

58+
pub fn is_empty(&self) -> bool {
59+
self.size == 0
60+
}
61+
5962
pub fn len(&self) -> usize {
6063
self.size
6164
}
@@ -67,7 +70,7 @@ impl StructuredScript {
6770
pub fn get_structured_script(&self, id: &u64) -> &StructuredScript {
6871
self.script_map
6972
.get(id)
70-
.expect(&format!("script id: {} not found in script_map.", id))
73+
.unwrap_or_else(|| panic!("script id: {} not found in script_map.", id))
7174
}
7275

7376
// Return the debug information of the Opcode at position
@@ -137,10 +140,10 @@ impl StructuredScript {
137140
}
138141

139142
pub fn push_env_script(mut self, mut data: StructuredScript) -> StructuredScript {
140-
if data.len() == 0 {
143+
if data.is_empty() {
141144
return self;
142145
}
143-
if self.len() == 0 {
146+
if self.is_empty() {
144147
return data;
145148
}
146149

@@ -308,8 +311,7 @@ impl NotU8Pushable for u32 {
308311
}
309312
impl NotU8Pushable for usize {
310313
fn bitcoin_script_push(self, builder: StructuredScript) -> StructuredScript {
311-
builder
312-
.push_int(i64::try_from(self).unwrap_or_else(|_| panic!("Usize does not fit in i64")))
314+
builder.push_int(i64::try_from(self).expect("Usize does not fit in i64"))
313315
}
314316
}
315317
impl NotU8Pushable for Vec<u8> {

0 commit comments

Comments
 (0)