This document describes migration to the split reference model:
LocalRef<M>: local-only, zero-overhead hot pathRemoteRef<C>: remote wire contractAnyRef<C>/Addr<C>: optional location-transparent wrapper
The goal is to preserve local performance while making remote usage explicit and type-safe.
Previous mixed usage tends to blur local and remote semantics. The split model enforces:
- Local call sites stay local-only (
LocalRef<M>). - Remote call sites declare a wire contract (
RemoteRef<C>+RefContract). - Location transparency is opt-in (
AnyRef<C>), not default.
- Existing generated actor refs keep working.
- For local-only call sites, switch to
as_local_ref()(orFromconversions). - For remote call sites, define a
RefContractand useRemoteRef<C>. - Only where needed, wrap local/remote as
AnyRef<C>.
Generated refs expose local conversion helpers.
let actor_ref = spawn.actor(); // e.g. MyActorRef
let local: axactor::LocalRef<MyActorMsg> = actor_ref.as_local_ref();
local.try_send(MyActorMsg::Ping {})?;LocalRef<M> uses the same mailbox path as local actor refs (MailboxTx<M>).
No remote serialization/network branch is introduced.
Define a remote contract with wire-safe types:
use axactor::RefContract;
struct ChatContract;
impl RefContract for ChatContract {
type Tell = ChatTell;
type Ask = ChatAsk;
type Reply = ChatReply;
}Then create remote ref:
let remote = axactor::RemoteRef::<ChatContract>::new(
client,
"room:general",
std::time::Duration::from_secs(1),
);Default codec is SimdJsonCodec.
Contract associated types are compile-time constrained by RemoteSafe.
Use only at explicit boundaries:
let any_local = axactor::AnyRef::local(local_contract_ref);
let any_remote = axactor::AnyRef::remote(remote_ref);AnyRef introduces a dispatch branch by design.
Avoid using it on local hot loops where static local refs are sufficient.
RemoteRefmonitor: uses cluster monitor/down protocol.AnyRef::monitor()is supported for both local and remote variants.- Local contract monitor requires explicit adapter:
let local = axactor::LocalContractRef::<MyContract>::new(tell, send_wait, ask)
.with_monitor_fn(|| Box::pin(async move {
// return mpsc::Receiver<axactor::cluster::DownEvent>
todo!()
}));Existing tests cover:
- ref API correctness (
axactor/tests/ref_api_test.rs) - UI compile-fail guardrails (
axactor/tests/ui/*.rs) - local hot-path benchmark smoke (
axactor/benches/local_ref_bench.rs)
Recommended checks:
cargo test -p axactor --test ref_api_test
cargo test -p axactor --test compile_tests
cargo test -p axactor --bench local_ref_bench -- --nocapture- Actor-internal and node-local services:
LocalRef - Cluster-facing APIs:
RemoteRef - Mixed boundaries (plugin/bus/router abstractions):
AnyRef