Skip to content

Commit

Permalink
macros: Don't use late initializator for get_item!, use let in macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyhunsen committed Jun 26, 2024
1 parent 5ba04d1 commit 175a4ad
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
8 changes: 2 additions & 6 deletions src/ledger/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ macro_rules! update_item {
/// Assigns an item from member to given assignee, which is guarded by a `Cell`.
#[macro_export]
macro_rules! get_item {
($member:expr, $assignee:expr) => {
$assignee = $member.take();
($member:expr, $assignee:ident) => {
let $assignee = $member.take();
$member.set($assignee.clone());
};
}
Expand All @@ -71,7 +71,6 @@ mod tests {
fn add_get_item_to_vec() {
let strct = Test::default();

let mut items: Vec<isize>;
get_item!(strct.vec_member_1, items);
assert_eq!(items.len(), 0);

Expand All @@ -86,7 +85,6 @@ mod tests {
fn update_member() {
let strct = Test::default();

let mut item: isize;
get_item!(strct.int_member_1, item);
assert_eq!(item, isize::default());

Expand All @@ -103,8 +101,6 @@ mod tests {
fn remove_item_from_vec() {
let strct = Test::default();

let mut items: Vec<isize>;

add_item_to_vec!(strct.vec_member_1, 0x45);
add_item_to_vec!(strct.vec_member_1, 0x1F);
add_item_to_vec!(strct.vec_member_1, 0x100);
Expand Down
4 changes: 1 addition & 3 deletions src/ledger/transactions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! # Transaction Related Ledger Operations
use super::{errors::LedgerError, Ledger};
use crate::{add_item_to_vec, get_item, ledger::address::UserCredential, return_vec_item};
use crate::{add_item_to_vec, get_item, return_vec_item};
use bitcoin::{absolute, Amount, OutPoint, ScriptBuf, Transaction, TxIn, TxOut, Txid, Witness};

impl Ledger {
Expand Down Expand Up @@ -49,7 +49,6 @@ impl Ledger {
}
/// Returns a transaction which matches the given txid.
pub fn get_transaction(&self, txid: Txid) -> Result<Transaction, LedgerError> {
let txs: Vec<Transaction>;
get_item!(self.transactions, txs);

let tx = txs
Expand Down Expand Up @@ -121,7 +120,6 @@ impl Ledger {

/// Creates a `TxIn` with some defaults.
pub fn create_txin(&self, txid: Txid, vout: u32) -> TxIn {
let credentials: Vec<UserCredential>;
get_item!(self.credentials, credentials);
let witness = match credentials.last() {
Some(c) => match c.to_owned().witness {
Expand Down

0 comments on commit 175a4ad

Please sign in to comment.