Skip to content

Commit 5b10db2

Browse files
authored
feat: default into_logs fn (#2539)
1 parent c04ef82 commit 5b10db2

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

crates/consensus-any/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
88
#![cfg_attr(not(feature = "std"), no_std)]
99

10-
#[cfg(feature = "serde")]
1110
extern crate alloc;
1211

1312
mod block;

crates/consensus-any/src/receipt/envelope.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use alloc::vec::Vec;
12
use alloy_consensus::{Eip658Value, Receipt, ReceiptWithBloom, TxReceipt};
23
use alloy_eips::{
34
eip2718::{Decodable2718, Eip2718Result, Encodable2718},
@@ -117,7 +118,14 @@ where
117118
}
118119

119120
fn logs(&self) -> &[T] {
120-
self.logs()
121+
Self::logs(self)
122+
}
123+
124+
fn into_logs(self) -> Vec<Self::Log>
125+
where
126+
Self::Log: Clone,
127+
{
128+
self.inner.receipt.logs
121129
}
122130
}
123131

crates/consensus/src/receipt/envelope.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ where
199199
fn logs(&self) -> &[T] {
200200
&self.as_receipt().unwrap().logs
201201
}
202+
203+
fn into_logs(self) -> Vec<Self::Log>
204+
where
205+
Self::Log: Clone,
206+
{
207+
self.into_receipt().logs
208+
}
202209
}
203210

204211
impl ReceiptEnvelope {

crates/consensus/src/receipt/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use alloc::vec::Vec;
12
use alloy_primitives::Bloom;
23
use alloy_rlp::BufMut;
34
use core::fmt;
@@ -81,6 +82,15 @@ pub trait TxReceipt: Clone + fmt::Debug + PartialEq + Eq + Send + Sync {
8182

8283
/// Returns the logs emitted by this transaction.
8384
fn logs(&self) -> &[Self::Log];
85+
86+
/// Consumes the type and returns the logs emitted by this transaction as a vector.
87+
#[auto_impl(keep_default_for(&, Arc))]
88+
fn into_logs(self) -> Vec<Self::Log>
89+
where
90+
Self::Log: Clone,
91+
{
92+
self.logs().to_vec()
93+
}
8494
}
8595

8696
/// Receipt type that knows how to encode itself with a [`Bloom`] value.

crates/consensus/src/receipt/receipts.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ where
9292
fn logs(&self) -> &[Self::Log] {
9393
&self.logs
9494
}
95+
96+
fn into_logs(self) -> Vec<Self::Log>
97+
where
98+
Self::Log: Clone,
99+
{
100+
self.logs
101+
}
95102
}
96103

97104
impl<T: Encodable> Receipt<T> {

0 commit comments

Comments
 (0)