From 807a5ecad9522d9f276c35ffce8bab3aa760fbd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ceyhun=20=C5=9Een?= Date: Tue, 11 Jun 2024 12:11:42 +0300 Subject: [PATCH] macros: Move them to their own file. --- src/ledger/macros.rs | 26 ++++++++++++++++++++++++++ src/ledger/mod.rs | 25 ++----------------------- 2 files changed, 28 insertions(+), 23 deletions(-) create mode 100644 src/ledger/macros.rs diff --git a/src/ledger/macros.rs b/src/ledger/macros.rs new file mode 100644 index 0000000..9640f7f --- /dev/null +++ b/src/ledger/macros.rs @@ -0,0 +1,26 @@ +//! # Macros +//! +//! Useful macros for Ledger crate. + +/// Adds a new item to a `Vec` member, guarded by a `Cell`. +#[macro_export] +macro_rules! add_item { + ($member:expr, $item:expr) => { + // Update item list. + let mut items = $member.take(); + items.push($item); + + // Commit new change. + $member.set(items); + }; +} +/// Returns item `Vec` of a member, guarded by a `Cell`. +#[macro_export] +macro_rules! get_item { + ($member:expr) => { + let items = $member.take(); + $member.set(items.clone()); + + return items; + }; +} diff --git a/src/ledger/mod.rs b/src/ledger/mod.rs index 94d7e1f..6ee7da3 100644 --- a/src/ledger/mod.rs +++ b/src/ledger/mod.rs @@ -5,6 +5,7 @@ //! This crate is designed to be used as immutable, because of the `RpcApi`'s //! immutable nature. +use crate::{add_item, get_item}; use bitcoin::{Address, Transaction, TxOut}; use bitcoin_simulator::database::Database; use std::{ @@ -13,31 +14,9 @@ use std::{ }; mod errors; +mod macros; mod transactions; -/// Adds a new item to a `Vec` member, guarded by a `Cell`. -#[macro_export] -macro_rules! add_item { - ($member:expr, $item:expr) => { - // Update item list. - let mut items = $member.take(); - items.push($item); - - // Commit new change. - $member.set(items); - }; -} -/// Returns item `Vec` of a member, guarded by a `Cell`. -#[macro_export] -macro_rules! get_item { - ($member:expr) => { - let items = $member.take(); - $member.set(items.clone()); - - return items; - }; -} - /// Mock Bitcoin ledger. pub struct Ledger { /// Private database interface. Data will be written to this temporary