tonarino / actor

A minimalist actor framework aiming for high performance and simplicity.
MIT License
40 stars 6 forks source link

For reference: Add Box<dyn fmt::Debug> to SendError, require Actor::Message: Debug #60

Closed strohel closed 2 years ago

strohel commented 2 years ago

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 be Sync. Because we erase the M type from SendError, we either require M to be Sync or we're not Sync at all.

(crosbeam::channel's TrySendError<M> doesn't suffer from such a problem, it is Sync when M is Sync and vice-versa).

skywhale commented 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()?

skywhale commented 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()?

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").

strohel commented 2 years ago

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."

strohel commented 2 years ago

Closing, this served mainly as a demonstration companion to #59.