pub struct Ap2Adapter { /* private fields */ }ap2 and payments only.Expand description
AP2 alpha adapter over the canonical commerce kernel.
The adapter fails closed: until a MerchantAuthorizationVerifier and a
UserAuthorizationVerifier are configured, every merchant, intent, and
payment authorization artifact is rejected with
Ap2Error::AuthorizationVerifierNotConfigured. Payment mandates are
single-use: a mandate that reached the payment backend is refused when
resubmitted, and a transaction executes at most one payment mandate.
Money movement is governed like a GovernedCheckoutService
checkout: the PaymentPolicySet is evaluated before a cart mandate creates a
checkout and before a payment mandate reaches the payment backend, the payment total
is reserved in the spend ledger and committed once the backend authorizes it, and an
optional PaymentAuditor records each decision before money moves.
§Example
use adk_payments::protocol::ap2::Ap2Adapter;
let adapter = Ap2Adapter::new(checkout, payments, transactions, evidence)
.with_merchant_authorization_verifier(merchant_jws_verifier)
.with_user_authorization_verifier(user_sd_jwt_verifier)
.with_intervention_service(interventions);Implementations§
Source§impl Ap2Adapter
impl Ap2Adapter
Sourcepub fn new(
checkout_service: Arc<dyn MerchantCheckoutService>,
payment_service: Arc<dyn PaymentExecutionService>,
transaction_store: Arc<dyn TransactionStore>,
evidence_store: Arc<dyn EvidenceStore>,
) -> Ap2Adapter
pub fn new( checkout_service: Arc<dyn MerchantCheckoutService>, payment_service: Arc<dyn PaymentExecutionService>, transaction_store: Arc<dyn TransactionStore>, evidence_store: Arc<dyn EvidenceStore>, ) -> Ap2Adapter
Creates a new AP2 adapter bound to the canonical checkout, journal, and evidence services.
No authorization verifier is configured, so every authorization
artifact is rejected until
with_merchant_authorization_verifier
and with_user_authorization_verifier
are called. Executed payment mandates are tracked in an
InMemoryPaymentMandateLedger unless
with_payment_mandate_ledger replaces it.
Payments are governed by [SpendLimitGuardrail::when_configured] until
with_payment_policies adds further policies.
Sourcepub fn with_payment_policies(self, policies: PaymentPolicySet) -> Ap2Adapter
pub fn with_payment_policies(self, policies: PaymentPolicySet) -> Ap2Adapter
Evaluates policies before every cart-mandate checkout creation and every payment
mandate execution.
When policies has no spend guardrail, [SpendLimitGuardrail::when_configured] is
added, which reserves against with_spend_ledger or the
caller’s ledger.
§Example
use adk_payments::guardrail::{AmountThresholdGuardrail, PaymentPolicySet};
let adapter = adapter.with_payment_policies(
PaymentPolicySet::new()
.with(AmountThresholdGuardrail::new(Some(5_000), Some(50_000)).with_currency("USD", 2)),
);Sourcepub fn with_spend_ledger(self, ledger: Arc<dyn SpendLedger>) -> Ap2Adapter
pub fn with_spend_ledger(self, ledger: Arc<dyn SpendLedger>) -> Ap2Adapter
Reserves payments against ledger, ahead of any ledger the caller supplies.
Sourcepub fn with_payment_auditor(self, auditor: PaymentAuditor) -> Ap2Adapter
pub fn with_payment_auditor(self, auditor: PaymentAuditor) -> Ap2Adapter
Records every governed decision with auditor before money moves, refusing a
payment whose decision cannot be recorded.
Sets the merchant authorization verifier used for cart mandates.
Sets the user authorization verifier used for intent and payment mandates.
Accepts any non-empty authorization artifact where no verifier is configured.
Development only. Forged merchant signatures and user authorizations
pass this check, so a payment mandate carrying any non-empty
user_authorization reaches the payment backend. Verifiers configured
through with_*_authorization_verifier still apply. Emits one warn!
when called.
Sourcepub fn with_payment_mandate_ledger(
self,
ledger: Arc<dyn PaymentMandateLedger>,
) -> Ap2Adapter
pub fn with_payment_mandate_ledger( self, ledger: Arc<dyn PaymentMandateLedger>, ) -> Ap2Adapter
Replaces the ledger that records consumed payment mandate identifiers.
Use shared durable storage when several adapter instances serve one merchant, so a mandate cannot be replayed against another instance.
Sourcepub fn with_intervention_service(
self,
intervention_service: Arc<dyn InterventionService>,
) -> Ap2Adapter
pub fn with_intervention_service( self, intervention_service: Arc<dyn InterventionService>, ) -> Ap2Adapter
Enables canonical intervention handling for AP2 return-to-user flows.
Sourcepub async fn submit_intent_mandate(
&self,
context: CommerceContext,
intent_mandate: IntentMandate,
authorization_artifact: Option<AuthorizationArtifact>,
) -> Result<TransactionRecord, AdkError>
pub async fn submit_intent_mandate( &self, context: CommerceContext, intent_mandate: IntentMandate, authorization_artifact: Option<AuthorizationArtifact>, ) -> Result<TransactionRecord, AdkError>
Starts or refreshes a human-not-present transaction from an intent mandate.
§Errors
Returns an error when the intent is expired, unsigned, fails user authorization verification, or lacks explicit autonomous authority constraints.
Sourcepub async fn submit_cart_mandate(
&self,
context: CommerceContext,
cart_mandate: CartMandate,
) -> Result<TransactionRecord, AdkError>
pub async fn submit_cart_mandate( &self, context: CommerceContext, cart_mandate: CartMandate, ) -> Result<TransactionRecord, AdkError>
Creates or updates canonical checkout state from a merchant cart mandate.
§Errors
Returns an error when the cart is expired, unsigned, fails merchant authorization verification, names a merchant other than the verified signer, carries invalid amounts, or violates the stored intent constraints for a human-not-present transaction.
Sourcepub async fn submit_payment_mandate(
&self,
context: CommerceContext,
payment_mandate: PaymentMandate,
) -> Result<PaymentExecutionResult, AdkError>
pub async fn submit_payment_mandate( &self, context: CommerceContext, payment_mandate: PaymentMandate, ) -> Result<PaymentExecutionResult, AdkError>
Executes or escalates a payment mandate against the canonical payment service.
The payment is attributed to the session’s app and the acting actor; see
submit_payment_mandate_as.
§Errors
Sourcepub async fn submit_payment_mandate_as(
&self,
context: CommerceContext,
payment_mandate: PaymentMandate,
caller: &PaymentCaller,
) -> Result<PaymentExecutionResult, AdkError>
pub async fn submit_payment_mandate_as( &self, context: CommerceContext, payment_mandate: PaymentMandate, caller: &PaymentCaller, ) -> Result<PaymentExecutionResult, AdkError>
Executes or escalates a payment mandate for caller against the canonical payment
service.
The mandate’s authorization is verified first, and a verification failure refuses the payment. The payment policies are then evaluated on the stored transaction at the mandate’s total: a denial, a refused or pending escalation, a refused spend reservation, or an audit record that cannot be written stops the payment before the mandate is consumed, so the same mandate can be resubmitted once approved.
Payment mandates are single-use. The mandate identifier is consumed in
the PaymentMandateLedger immediately before the payment backend is
called and recorded on the transaction afterwards, so a resubmitted
mandate never executes twice and a transaction never executes a second
mandate. The backend receives an idempotency_key extension field: the key
already on context (a payment tool supplies its call’s key), otherwise one
derived from the payment mandate ID.
§Errors
Returns an error when the mandate does not match the current cart, fails
user authorization verification, was already executed, targets a
transaction that already executed a payment or is bound to another
mandate, or the flow lacks user authorization and cannot proceed
autonomously. Returns payments.policy.denied,
payments.policy.approval_required, or payments.policy.approval_denied when
the payment policies stop the payment, and payments.auth.audit_failed when the
decision cannot be recorded.
Sourcepub async fn apply_payment_receipt(
&self,
context: CommerceContext,
payment_receipt: PaymentReceipt,
) -> Result<TransactionRecord, AdkError>
pub async fn apply_payment_receipt( &self, context: CommerceContext, payment_receipt: PaymentReceipt, ) -> Result<TransactionRecord, AdkError>
Applies a final AP2 payment receipt to canonical transaction state.
§Errors
Returns an error when the underlying transaction does not exist or the receipt references a payment mandate other than the one bound to the transaction.
Auto Trait Implementations§
impl !RefUnwindSafe for Ap2Adapter
impl !UnwindSafe for Ap2Adapter
impl Forget for Ap2Adapter
impl Freeze for Ap2Adapterwhere
*const ArcInner<dyn MerchantCheckoutService> is !null: Freeze,
PhantomData<ArcInner<dyn MerchantCheckoutService>>: Freeze,
*const ArcInner<dyn PaymentExecutionService> is !null: Freeze,
PhantomData<ArcInner<dyn PaymentExecutionService>>: Freeze,
*const ArcInner<dyn TransactionStore> is !null: Freeze,
PhantomData<ArcInner<dyn TransactionStore>>: Freeze,
*const ArcInner<dyn EvidenceStore> is !null: Freeze,
PhantomData<ArcInner<dyn EvidenceStore>>: Freeze,
*const ArcInner<dyn MerchantAuthorizationVerifier> is !null: Freeze,
PhantomData<ArcInner<dyn MerchantAuthorizationVerifier>>: Freeze,
*const ArcInner<dyn UserAuthorizationVerifier> is !null: Freeze,
PhantomData<ArcInner<dyn UserAuthorizationVerifier>>: Freeze,
*const ArcInner<dyn PaymentMandateLedger> is !null: Freeze,
PhantomData<ArcInner<dyn PaymentMandateLedger>>: Freeze,
*const ArcInner<dyn InterventionService> is !null: Freeze,
PhantomData<ArcInner<dyn InterventionService>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<Arc<dyn PaymentPolicyGuardrail>>: Freeze,
*const ArcInner<dyn SpendLedger> is !null: Freeze,
PhantomData<ArcInner<dyn SpendLedger>>: Freeze,
*const ArcInner<dyn AuditSink> is !null: Freeze,
PhantomData<ArcInner<dyn AuditSink>>: Freeze,
impl Move for Ap2Adapter
impl Send for Ap2Adapterwhere
Arc<dyn MerchantCheckoutService>: Send,
Arc<dyn PaymentExecutionService>: Send,
Arc<dyn TransactionStore>: Send,
Arc<dyn EvidenceStore>: Send,
Arc<dyn MerchantAuthorizationVerifier>: Send,
Arc<dyn UserAuthorizationVerifier>: Send,
Arc<dyn PaymentMandateLedger>: Send,
Arc<dyn InterventionService>: Send,
RawVecInner: Send,
Arc<dyn PaymentPolicyGuardrail>: Send,
Arc<dyn SpendLedger>: Send,
Arc<dyn AuditSink>: Send,
impl Sync for Ap2Adapterwhere
Arc<dyn MerchantCheckoutService>: Sync,
Arc<dyn PaymentExecutionService>: Sync,
Arc<dyn TransactionStore>: Sync,
Arc<dyn EvidenceStore>: Sync,
Arc<dyn MerchantAuthorizationVerifier>: Sync,
Arc<dyn UserAuthorizationVerifier>: Sync,
Arc<dyn PaymentMandateLedger>: Sync,
Arc<dyn InterventionService>: Sync,
RawVecInner: Sync,
Arc<dyn PaymentPolicyGuardrail>: Sync,
Arc<dyn SpendLedger>: Sync,
Arc<dyn AuditSink>: Sync,
impl Unpin for Ap2Adapterwhere
Arc<dyn MerchantCheckoutService>: Unpin,
Arc<dyn PaymentExecutionService>: Unpin,
Arc<dyn TransactionStore>: Unpin,
Arc<dyn EvidenceStore>: Unpin,
Arc<dyn MerchantAuthorizationVerifier>: Unpin,
Arc<dyn UserAuthorizationVerifier>: Unpin,
Arc<dyn PaymentMandateLedger>: Unpin,
Arc<dyn InterventionService>: Unpin,
*const u8 is !null: Unpin,
Arc<dyn PaymentPolicyGuardrail>: Unpin,
Arc<dyn SpendLedger>: Unpin,
Arc<dyn AuditSink>: Unpin,
impl UnsafeUnpin for Ap2Adapterwhere
*const ArcInner<dyn MerchantCheckoutService> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn MerchantCheckoutService>>: UnsafeUnpin,
*const ArcInner<dyn PaymentExecutionService> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn PaymentExecutionService>>: UnsafeUnpin,
*const ArcInner<dyn TransactionStore> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn TransactionStore>>: UnsafeUnpin,
*const ArcInner<dyn EvidenceStore> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn EvidenceStore>>: UnsafeUnpin,
*const ArcInner<dyn MerchantAuthorizationVerifier> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn MerchantAuthorizationVerifier>>: UnsafeUnpin,
*const ArcInner<dyn UserAuthorizationVerifier> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn UserAuthorizationVerifier>>: UnsafeUnpin,
*const ArcInner<dyn PaymentMandateLedger> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn PaymentMandateLedger>>: UnsafeUnpin,
*const ArcInner<dyn InterventionService> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn InterventionService>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Arc<dyn PaymentPolicyGuardrail>>: UnsafeUnpin,
*const ArcInner<dyn SpendLedger> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn SpendLedger>>: UnsafeUnpin,
*const ArcInner<dyn AuditSink> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn AuditSink>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> MaybeSend for Twhere
T: Send,
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.