Skip to content

Supertrait seal {send,receive}::..State traits#994

Merged
DanGould merged 1 commit intopayjoin:masterfrom
DanGould:seal-state-trait
Aug 28, 2025
Merged

Supertrait seal {send,receive}::..State traits#994
DanGould merged 1 commit intopayjoin:masterfrom
DanGould:seal-state-trait

Conversation

@DanGould
Copy link
Copy Markdown
Contributor

@DanGould DanGould commented Aug 26, 2025

These traits are in the public API but not for downstream users to implement. Close #747

Here's an article on what the heck that means: https://predr.ag/blog/definitive-guide-to-sealed-traits-in-rust/

Pull Request Checklist

Please confirm the following before requesting review:

  • A human has reviewed every single line of this code before opening the PR (no auto-generated, unreviewed LLM/robot submissions).
  • I have read CONTRIBUTING.md and rebased my branch to produce hygienic commits.

@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Aug 26, 2025

Pull Request Test Coverage Report for Build 17305417442

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 85.78%

Totals Coverage Status
Change from base Build 17305364020: 0.0%
Covered Lines: 8041
Relevant Lines: 9374

💛 - Coveralls

@DanGould
Copy link
Copy Markdown
Contributor Author

Pls @arminsabouri my 1.0 famili depends on it

These traits are in the public API but not for downstream users to implement.
Close payjoin#747
Copy link
Copy Markdown
Collaborator

@arminsabouri arminsabouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK
Can confirm you cannot impl State outside the crate

struct x {};
impl payjoin::receive::v2::State for x {};

Results in

the trait bound `x: payjoin::receive::v2::sealed::State` is not satisfied
the following other types implement trait `payjoin::receive::v2::sealed::State`:
  payjoin::receive::v2::Initialized
  payjoin::receive::v2::MaybeInputsOwned
  payjoin::receive::v2::MaybeInputsSeen
  payjoin::receive::v2::OutputsUnknown
  payjoin::receive::v2::PayjoinProposal
  payjoin::receive::v2::ProvisionalProposal
  payjoin::receive::v2::UncheckedProposal
  payjoin::receive::v2::WantsFeeRange
and 2 others
`State` is a "sealed trait", because to implement it you also need to implement `payjoin::receive::v2::sealed::State`, which is not accessible; this is usually done to force you to use one of the provided types that already implement it

@DanGould DanGould merged commit 27e3876 into payjoin:master Aug 28, 2025
10 checks passed
@DanGould DanGould deleted the seal-state-trait branch August 28, 2025 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

use sealed traits for State traits

3 participants