Skip to content

Commit 53585d0

Browse files
committed
Improve actor builder documentation
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
1 parent 4e3febb commit 53585d0

File tree

7 files changed

+29
-37
lines changed

7 files changed

+29
-37
lines changed

crates/core/tedge_actors/src/builders.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@
4747
//! (possibly several receivers to handle message priorities among inputs),
4848
//! and has to give clones of the associated Sender (or Senders) to its peers.
4949
//! - The first responsibility of a builder is to create a channel per receiver of the actor
50-
//! under construction. The receiver will be given to the actor on build.
50+
//! under construction. The receiver will be given to the actor when built.
5151
//! The sender is owned by the builder to be cloned and given to any peer that needs to send data
5252
//! to the actor under construction.
53-
//! - The second responsibility of the builder is to collect a Sender for each peer the actor
53+
//! - The second responsibility of the builder is to collect a sender for each peer the actor
5454
//! under construction needs to send messages to. This is the mirror of the previous responsibility:
5555
//! each builder gives to the others clones of its senders and collects senders from others.
5656
//! - This is why all the actor building traits
5757
//! ([MessageSource], [MessageSink] and [RuntimeRequestSink])
58-
//! are related to exchanges of Sender. A sink gives to a source a sender attached to its receiver.
59-
//! - To be precise, the actor builders exchange [DynSender] and not [Sender]. The difference is that
60-
//! a [DynSender] can transform the messages sent by the source to adapt them to the sink expectations,
58+
//! are related to exchanges of Sender. A sink gives to a source a sender attached to its own receiver.
59+
//! - To be precise, the actor builders exchange [DynSender] and not [Sender](futures::channel::mpsc::Sender).
60+
//! The difference is that a [DynSender] can transform the messages sent by the source to adapt them to the sink expectations,
6161
//! using an `impl From<SourceMessage> for SinkMessage`. This flexibility allows an actor to receive
6262
//! messages from several independent sources (see the [fan_in_message_type](crate::fan_in_message_type) macro).
6363
use crate::mpsc;

crates/core/tedge_actors/src/channels.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub trait CloneSender<M>: Sender<M> {
2525

2626
/// Clone a cast of this sender into a `Box<dyn Sender<M>>`
2727
///
28-
/// This is a workaround for https://github.com/rust-lang/rust/issues/65991
28+
/// This is a workaround for <https://github.com/rust-lang/rust/issues/65991>
2929
fn sender(&self) -> Box<dyn Sender<M>>;
3030
}
3131

crates/core/tedge_actors/src/lib.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//!
55
//! Actors are processing units that interact using asynchronous messages.
66
//!
7-
//! The behavior of an [Actor](crate::Actor) is defined by:
7+
//! The behavior of an [Actor] is defined by:
88
//! - a state owned and freely updated by the actor,
99
//! - a [message box](crate::message_boxes) connected to peer actors,
1010
//! - input [messages](crate::Message) that the actor receives from its peers and processes in turn,
@@ -87,9 +87,9 @@
8787
//! ```
8888
//!
8989
//! This crate provides specific `Actor` implementations:
90-
//! - The [ServerActor](crate::ServerActor) wraps a [Server](crate::Server),
90+
//! - The [ServerActor] wraps a [Server],
9191
//! to implement a request-response communication pattern with a set of connected client actors.
92-
//! - The [ConvertingActor](crate::ConvertingActor) wraps a [Converter](crate::Converter),
92+
//! - The [ConvertingActor] wraps a [Converter],
9393
//! that translates each input message into a sequence of output messages.
9494
//!
9595
//! ## Testing an actor
@@ -104,9 +104,8 @@
104104
//! [Actor and message box builders](crate::builders) are provided to address these specificities
105105
//! with a generic approach without exposing the internal structure of the actors.
106106
//!
107-
//! To test the `Calculator` example we need first to create its box using a
108-
//! [SimpleMessageBoxBuilder](crate::SimpleMessageBoxBuilder),
109-
//! as this actor expects a [SimpleMessageBox](crate::SimpleMessageBox).
107+
//! To test the `Calculator` example we need first to create its box using a [SimpleMessageBoxBuilder],
108+
//! as this actor expects a [SimpleMessageBox].
110109
//! And then, to create a test box connected to the actor message box,
111110
//! we use the [ServiceProviderExt](crate::test_helpers::ServiceProviderExt) test helper extension
112111
//! and the [new_client_box](crate::test_helpers::ServiceProviderExt::new_client_box) method.
@@ -153,7 +152,7 @@
153152
//! # }
154153
//! ```
155154
//!
156-
//! See the [test_helpers](crate::test_helpers) module for various ways
155+
//! See the [test_helpers] module for various ways
157156
//! to observe and interact with running actors.
158157
//!
159158
//! - The primary tool to interact with an actor under test is the [SimpleMessageBoxBuilder],
@@ -172,26 +171,20 @@
172171
//! that define the services provided and consumed by the actors under construction.
173172
//!
174173
//! The connection builder traits work by pairs.
175-
//! A [MessageSink](crate::MessageSink) connects to a [MessageSource](crate::MessageSource),
174+
//! A [MessageSink] connects to a [MessageSource],
176175
//! so the messages sent by the latter will be received by the former.
177176
//!
178177
//! These traits define the types of the messages sent and received.
179178
//! - A sink that excepts message of type `M` can only be connected to a source of messages
180179
//! that can be converted into `M` values.
181-
//! - Similarly a service is defined by two types of messages, the requests received by the service
182-
//! and the responses sent by the service. To use a service, a consumer will have to send messages
183-
//! that can be converted into the service request type and be ready to receive messages converted from
184-
//! the service response type.
185180
//! - Note, that no contract is enforced beyond the type-compatibility of the messages sent between the actors.
186181
//! A consumer of an HTTP service needs to known that a request must be sent before any response can be received;
187182
//! while a consumer of an MQTT service can expect to receive messages without sending a single one.
188183
//!
189184
//! The connection builder traits also define a configuration type.
190-
//! - The semantics of this type is defined by the message source or the service provider.
191-
//! It can be used to filter the values sent to a given sink
192-
//! or to restrict the scope of the service provided to a given service consumer.
193-
//! - The configuration values are provided by the message sinks and the service consumers
194-
//! to specify the context of their connection to a source or a service.
185+
//! - The semantics of this type is defined by the message source and is used to filter the values sent to a sink.
186+
//! - The actual configuration values are provided by the actor sinks when connecting the source
187+
//! to specify the subset of messages their are interested into.
195188
//!
196189
//! Note that these traits are implemented by the actor builders, not by the actors themselves.
197190
//!

crates/core/tedge_actors/src/message_boxes.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
//! Conceptually, a message box is a receiver of input messages combined with a sender of output messages.
88
//! * The receiver is connected to the senders of peer actors;
99
//! and reciprocally the sender is connected to receivers of peer actors.
10-
//! * The receivers are [mpsc::Receiver](crate::mpsc::Receiver) that collect messages from several sources,
10+
//! * The receivers are [mpsc::Receiver] that collect messages from several sources,
1111
//! and deliver the messages to the actor in the order they have been received.
12-
//! * The senders are [DynSender](crate::DynSender) that adapt the messages sent to match constraints of the receivers.
12+
//! * The senders are [DynSender] that adapt the messages sent to match constraints of the receivers.
1313
//!
14-
//! A [SimpleMessageBox](crate::SimpleMessageBox) implements exactly this conceptual view:
14+
//! A [SimpleMessageBox] implements exactly this conceptual view:
1515
//!
1616
//! ```ascii
1717
//! input_senders: DynSender<Input> ...
@@ -79,7 +79,7 @@
7979
//!
8080
//! This crates provides several built-in message box implementations:
8181
//!
82-
//! - [SimpleMessageBox](crate::SimpleMessageBox) for actors that simply process messages in turn,
82+
//! - [SimpleMessageBox] for actors that simply process messages in turn,
8383
//! - [ServerMessageBox](crate::ServerMessageBox) for server actors that deliver a request-response service,
8484
//! - [ConcurrentServerMessageBox](crate::ConcurrentServerMessageBox) for server actors that process requests concurrently,
8585
//! - [ClientMessageBox](crate::ClientMessageBox) for client actors that use a request-response service from a server actor,

crates/core/tedge_actors/src/servers/message_boxes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<Request: Message, Response: Message> Clone for ClientMessageBox<Request, Re
109109
}
110110

111111
impl<Request: Message, Response: Message> ClientMessageBox<Request, Response> {
112-
/// Create a [ClientMessageBox] connected to a given [Server]
112+
/// Create a [ClientMessageBox] connected to a given [Server](crate::Server)
113113
pub fn new(server: &mut impl MessageSink<RequestEnvelope<Request, Response>>) -> Self {
114114
ClientMessageBox {
115115
sender: server.get_sender(),

crates/core/tedge_actors/src/servers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
//! }
4848
//! ```
4949
//!
50-
//! To be used as an actor, a `Server` is wrapped into a [ServerActor](crate::ServerActor)
50+
//! To be used as an actor, a `Server` is wrapped into a [ServerActor]
5151
//!
5252
//! ```
5353
//! # use tedge_actors::{Actor, Builder, NoConfig, MessageReceiver, Sender, ServerActorBuilder, ServerConfig, Sequential};

crates/core/tedge_actors/src/test_helpers.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ use futures::StreamExt;
399399
/// The two actors under test, as well as their message boxes, are built and launched as usual,
400400
/// the only interaction being on the wire:
401401
/// - A probe is set on one side using the [with_probe()](crate::test_helpers::ServiceConsumerExt::with_probe)
402-
/// method added by the [ServiceConsumerExt](crate::test_helpers::ServiceConsumerExt)
402+
/// method added by the [ServiceConsumerExt]
403403
/// to any actor or message box builder.
404404
/// - The [Probe::observe()](crate::test_helpers::Probe::observe) method can then be used
405405
/// to observe all the messages either [sent](crate::test_helpers::ProbeEvent::Send)
@@ -459,7 +459,7 @@ pub struct Probe<I: MessagePlus, O: MessagePlus> {
459459
output_forwarder: DynSender<O>,
460460
}
461461

462-
/// An event observed by a [Probe](crate::test_helpers::Probe)
462+
/// An event observed by a [Probe]
463463
///
464464
/// These events have to be interpreted from the point of view of
465465
/// the actor on which the probe has been set.
@@ -491,8 +491,7 @@ impl<I: MessagePlus, O: MessagePlus> Probe<I, O> {
491491
/// Create a new `Probe` ready to be interposed between two actors.
492492
///
493493
/// The connection is done using the [with_probe()](crate::test_helpers::ServiceConsumerExt::with_probe)
494-
/// method added to any [ServiceConsumer](crate::ServiceConsumer)
495-
/// by [ServiceConsumerExt](crate::test_helpers::ServiceConsumerExt).
494+
/// method added by [ServiceConsumerExt] to any actor builder implementing [MessageSource] and [MessageSink].
496495
pub fn new() -> Self {
497496
// The capacity of the interceptor channels is 1,
498497
// so the probe will control at which pace input/output messages are sent.
@@ -598,15 +597,15 @@ impl<I: MessagePlus, O: MessagePlus> Probe<I, O> {
598597
}
599598
}
600599

601-
/// Extend any [ServiceConsumer] with a `with_probe` method.
600+
/// Extend with a `with_probe` method any actor builder implementing [MessageSource] and [MessageSink].
602601
pub trait ServiceConsumerExt<Request: MessagePlus, Response: MessagePlus> {
603-
/// Add a probe to an actor `self` that is a [MessageSource](crate::MessageSource) and [MessageSink](crate::MessageSink).
602+
/// Add a probe to an actor `self` that is a [MessageSource] and [MessageSink].
604603
///
605-
/// Return a [MessageSource](crate::MessageSource) and [MessageSink](crate::MessageSink)
604+
/// Return a [MessageSource] and [MessageSink]
606605
/// that can be plugged into another actor which consumes the source messages and produces messages for the sink.
607606
///
608607
/// The added `Probe` is then interposed between the two actors,
609-
/// observing all the [ProbeEvent](crate::test_helpers::ProbeEvent) exchanged between them.
608+
/// observing all the [ProbeEvent] exchanged between them.
610609
///
611610
/// ```
612611
/// # use tedge_actors::{NoConfig, ServerMessageBoxBuilder, SimpleMessageBoxBuilder};

0 commit comments

Comments
 (0)