Skip to content

Commit 865c1bd

Browse files
andrewjcgfacebook-github-bot
authored andcommitted
Add CanSend impls for reference types too (#442)
Summary: Pull Request resolved: #442 This makes it easier to use a generic to represent either `&Context<>` (borrowed), `&Mailbox` (borrowed), or `Mailbox` (owned). Reviewed By: mariusae Differential Revision: D77868301 fbshipit-source-id: 8544fed8321804f24e312af47609eac4b7188240
1 parent dd34e31 commit 865c1bd

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

hyperactor/src/mailbox.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,17 @@ impl cap::sealed::CanSend for Mailbox {
13231323
MailboxSender::post(self, envelope, return_handle);
13241324
}
13251325
}
1326+
impl cap::sealed::CanSend for &Mailbox {
1327+
fn post(&self, dest: PortId, headers: Attrs, data: Serialized) {
1328+
cap::sealed::CanSend::post(*self, dest, headers, data)
1329+
}
1330+
}
1331+
1332+
impl cap::sealed::CanOpenPort for &Mailbox {
1333+
fn mailbox(&self) -> &Mailbox {
1334+
self
1335+
}
1336+
}
13261337

13271338
impl cap::sealed::CanOpenPort for Mailbox {
13281339
fn mailbox(&self) -> &Mailbox {

hyperactor/src/proc.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,12 +1195,24 @@ impl<A: Actor> cap::sealed::CanSend for Instance<A> {
11951195
}
11961196
}
11971197

1198+
impl<A: Actor> cap::sealed::CanSend for &Instance<A> {
1199+
fn post(&self, dest: PortId, headers: Attrs, data: Serialized) {
1200+
(*self).post(dest, headers, data)
1201+
}
1202+
}
1203+
11981204
impl<A: Actor> cap::sealed::CanOpenPort for Instance<A> {
11991205
fn mailbox(&self) -> &Mailbox {
12001206
&self.mailbox
12011207
}
12021208
}
12031209

1210+
impl<A: Actor> cap::sealed::CanOpenPort for &Instance<A> {
1211+
fn mailbox(&self) -> &Mailbox {
1212+
&self.mailbox
1213+
}
1214+
}
1215+
12041216
impl<A: Actor> cap::sealed::CanSplitPort for Instance<A> {
12051217
fn split(&self, port_id: PortId, reducer_spec: Option<ReducerSpec>) -> anyhow::Result<PortId> {
12061218
self.mailbox.split(port_id, reducer_spec)
@@ -1234,12 +1246,24 @@ impl<A: Actor> cap::sealed::CanSend for Context<'_, A> {
12341246
}
12351247
}
12361248

1249+
impl<A: Actor> cap::sealed::CanSend for &Context<'_, A> {
1250+
fn post(&self, dest: PortId, headers: Attrs, data: Serialized) {
1251+
<Instance<A> as cap::sealed::CanSend>::post(self, dest, headers, data)
1252+
}
1253+
}
1254+
12371255
impl<A: Actor> cap::sealed::CanOpenPort for Context<'_, A> {
12381256
fn mailbox(&self) -> &Mailbox {
12391257
<Instance<A> as cap::sealed::CanOpenPort>::mailbox(self)
12401258
}
12411259
}
12421260

1261+
impl<A: Actor> cap::sealed::CanOpenPort for &Context<'_, A> {
1262+
fn mailbox(&self) -> &Mailbox {
1263+
<Instance<A> as cap::sealed::CanOpenPort>::mailbox(self)
1264+
}
1265+
}
1266+
12431267
impl<A: Actor> cap::sealed::CanSplitPort for Context<'_, A> {
12441268
fn split(&self, port_id: PortId, reducer_spec: Option<ReducerSpec>) -> anyhow::Result<PortId> {
12451269
<Instance<A> as cap::sealed::CanSplitPort>::split(self, port_id, reducer_spec)

0 commit comments

Comments
 (0)