Skip to content

Comments

feat: add trait impls for Cow to support Recovered<Cow<'_, T>>#3689

Merged
mattsse merged 1 commit intomainfrom
mattsse/cow-trait-impls
Feb 14, 2026
Merged

feat: add trait impls for Cow to support Recovered<Cow<'_, T>>#3689
mattsse merged 1 commit intomainfrom
mattsse/cow-trait-impls

Conversation

@gakonst
Copy link
Member

@gakonst gakonst commented Feb 14, 2026

Adds Cow<'_, T> implementations for key traits so that Recovered<Cow<'_, T>> works transparently. This enables pool transaction types to return either borrowed or owned consensus transactions via Cow.

Changes

  • Typed2718 for Cow<'_, T> in alloy-eips
  • Encodable2718 for Cow<'_, T> in alloy-eips
  • TxHashRef for Cow<'_, T> in alloy-consensus
  • Recovered<Cow<'_, T>>::into_owned() helper in alloy-consensus

Context

reth's PoolTransaction trait needs a consensus_ref method that returns Recovered<Cow<'_, Self::Consensus>>. Types wrapping the consensus tx return Cow::Borrowed, while mock/test types that don't store a consensus tx can return Cow::Owned. These impls make Recovered<Cow<'_, T>> a first-class citizen.

Transaction itself can't be impl'd for Cow<'a, T> due to the 'static supertrait bound, but callers access Transaction methods through deref coercion.

Prompted by: matthias

Add Cow<'_, T> implementations for key traits:
- Typed2718
- Encodable2718
- TxHashRef

Add Recovered<Cow<'_, T>>::into_owned() helper.

Amp-Thread-ID: https://ampcode.com/threads/T-019c5c07-e7dd-74c9-8640-a59cc70697a9
Co-authored-by: Amp <[email protected]>
@github-project-automation github-project-automation bot moved this to Reviewed in Alloy Feb 14, 2026
@mattsse mattsse merged commit 1c4296e into main Feb 14, 2026
25 of 30 checks passed
@mattsse mattsse deleted the mattsse/cow-trait-impls branch February 14, 2026 12:44
@github-project-automation github-project-automation bot moved this from Reviewed to Done in Alloy Feb 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants