1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//! Atomic construction of an unstarted reactor and its bounded ingress authority.
use crate::{
MailboxLimits, MailboxReceiver, MailboxSender, Reactor, Retained, RetainedBytes, WakeHandle,
mailbox, mailbox_with,
};
use super::ReactorId;
/// One unstarted reactor and the exact mailbox sender routed to its duty.
#[derive(Debug)]
pub struct ReactorGroupMember<D, C, W, T> {
id: ReactorId,
reactor: Reactor<D, C, W>,
ingress: MailboxSender<T>,
}
impl<D, C, W, T> ReactorGroupMember<D, C, W, T> {
/// Mints a bounded mailbox and constructs its sole reactor owner.
///
/// The declared identity is passed to the factory and must match this
/// member's eventual position in the static topology.
///
/// The sender is not exposed before group admission wraps it. The factory
/// must move the supplied receiver into the returned reactor duty.
pub fn with_mailbox(
id: ReactorId,
limits: MailboxLimits,
wake: WakeHandle,
reactor: impl FnOnce(ReactorId, MailboxReceiver<T>) -> Reactor<D, C, W>,
) -> Self
where
T: Retained,
{
let (ingress, receiver) = mailbox(limits, wake);
Self {
id,
reactor: reactor(id, receiver),
ingress,
}
}
/// Mints a measured bounded mailbox and constructs its sole reactor owner.
///
/// The declared identity is passed to the factory and must match this
/// member's eventual position in the static topology.
///
/// The measurement function follows [`crate::mailbox_with`]. The factory
/// must move the supplied receiver into the returned reactor duty.
pub fn with_mailbox_measure(
id: ReactorId,
limits: MailboxLimits,
measure: fn(&T) -> RetainedBytes,
wake: WakeHandle,
reactor: impl FnOnce(ReactorId, MailboxReceiver<T>) -> Reactor<D, C, W>,
) -> Self {
let (ingress, receiver) = mailbox_with(limits, measure, wake);
Self {
id,
reactor: reactor(id, receiver),
ingress,
}
}
pub(super) const fn from_parts(
id: ReactorId,
reactor: Reactor<D, C, W>,
ingress: MailboxSender<T>,
) -> Self {
Self {
id,
reactor,
ingress,
}
}
/// Returns the declared static topology identity.
pub const fn id(&self) -> ReactorId {
self.id
}
/// Returns shared access to the unstarted reactor.
pub const fn reactor(&self) -> &Reactor<D, C, W> {
&self.reactor
}
pub(super) fn into_parts(self) -> (ReactorId, Reactor<D, C, W>, MailboxSender<T>) {
(self.id, self.reactor, self.ingress)
}
}