Closed strohel closed 2 years ago
I haven't looked into deep enough, but could we do something along the line of crossbeam
i.e. return SendError<N: Debug + Sync>
for M: Sync
, and SendError<N: Debug>
for M
(non-Sync)? I guess not, without having two variants of recipient()
?
I haven't looked into deep enough, but could we do something along the line of
crossbeam
i.e. returnSendError<N: Debug + Sync>
forM: Sync
, andSendError<N: Debug>
forM
(non-Sync)? I guess not, without having two variants ofrecipient()
?
Ah, you answered already in https://github.com/tonarino/actor/pull/59.
The ideal API would probably be: provide Option<Box
> in SendError which would be Some if M: Debug and None otherwise. Maybe specialization would allow this one day, but I see no way how to achieve that in current stable rust (it looks like one can "require" a bound, but cannot "detect optional bound being satisfied").
Ah, you answered already in #59.
Yep, we're basically hitting the same limitation. SendError<N>
is parametrized by some N
(which is convertible to M
), but whether such SendError
is Sync
depends on M
, not N
, so we cannot (AFAICS) use the type system to "automatically propagate additional invariants from M
to SendError
."
Closing, this served mainly as a demonstration companion to #59.
An alternative to #59, doesn't build.
Add test for SendError
We're going to touch it, the tests will demonstrate the changes.
Add Box to SendError, require Actor::Message: Debug
The problem: does not compile, because popular error libraries like
anyhow
require the error to beSync
. Because we erase theM
type from SendError, we either requireM
to beSync
or we're notSync
at all.(crosbeam::channel's
TrySendError<M>
doesn't suffer from such a problem, it isSync
when M isSync
and vice-versa).