Skip to content

Commit

Permalink
feat: add into transactions iterator (alloy-rs#984)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored and ben186 committed Jul 27, 2024
1 parent 70f951d commit f3227b5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/rpc-types-eth/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ impl<T> BlockTransactions<T> {
}

/// Fallibly cast to a slice of transactions.
///
/// Returns `None` if the enum variant is not `Full`.
pub fn as_transactions(&self) -> Option<&[T]> {
match self {
Self::Full(txs) => Some(txs),
Expand All @@ -211,6 +213,15 @@ impl<T> BlockTransactions<T> {
self.as_transactions().map(|txs| txs.iter()).unwrap_or_else(|| [].iter())
}

/// Returns an iterator over the transactions (if any). This will be empty if the block is not
/// full.
pub fn into_transactions(self) -> std::vec::IntoIter<T> {
match self {
Self::Full(txs) => txs.into_iter(),
_ => std::vec::IntoIter::default(),
}
}

/// Returns an instance of BlockTransactions with the Uncle special case.
#[inline]
pub const fn uncle() -> Self {
Expand Down

0 comments on commit f3227b5

Please sign in to comment.