Struct hollywood::core::out_request::OutRequestChannel

source ·
pub struct OutRequestChannel<Request, Reply, M: IsInboundMessage> {
    pub name: String,
    pub actor_name: String,
    /* private fields */
}
Expand description

OutRequestChannel is a connections for sending requests to other actors (and receiving replies later).

Fields§

§name: String

Unique name of the request channel.

§actor_name: String

Name of the actor that sends the request messages.

Implementations§

source§

impl<Request: Clone + Send + Sync + Debug + 'static, Reply: Clone + Send + Sync + Debug + 'static, M: IsInboundMessageNew<ReplyMessage<Reply>>> OutRequestChannel<Request, Reply, M>

source

pub fn new(name: String, actor_name: &str, sender: &UnboundedSender<M>) -> Self

Creates a new out-request channel for the actor.

source

pub fn connect<Me: IsInRequestMessageNew<RequestWithReplyChannel<Request, Reply>>>( &mut self, _ctx: &mut Hollywood, inbound: &mut InRequestChannel<RequestWithReplyChannel<Request, Reply>, Me> )

Connects the out-request channel from this actor to the in-request channel of another actor.

Examples found in repository?
examples/egui.rs (line 319)
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
pub async fn run_viewer_example() {
    let mut builder = EguiAppExampleBuilder::from_config(EguiAppExampleAppConfig {});

    // Pipeline configuration
    let pipeline = Hollywood::configure(&mut |context| {
        // Actor creation:
        // 1. Periodic timer to drive the simulation
        let mut timer = hollywood::actors::Periodic::new_with_period(context, 0.1);
        // 2. The content generator of the example
        let mut content_generator = ContentGenerator::from_prop_and_state(
            context,
            NullProp::default(),
            ContentGeneratorState {
                last_x: 0.0,
                offset: 0.0,
            },
        );
        // 3. The egui actor
        let mut egui_actor =
            EguiActor::<PlotMessage, String, String, (), f64>::from_builder(context, &builder);

        // Pipeline connections:
        timer
            .outbound
            .time_stamp
            .connect(context, &mut content_generator.inbound.tick);
        content_generator
            .outbound
            .plot_message
            .connect(context, &mut egui_actor.inbound.stream);

        egui_actor
            .out_requests
            .request
            .connect(context, &mut content_generator.in_requests.reset);

        content_generator
            .out_requests
            .example_request
            .connect(context, &mut egui_actor.in_requests.request);
    });

    // The cancel_requester is used to cancel the pipeline.
    builder
        .cancel_request_sender
        .clone_from(&pipeline.cancel_request_sender_template);

    // Plot the pipeline graph to the console.
    pipeline.print_flow_graph();

    // Pipeline execution:

    // 1. Run the pipeline on a separate thread.
    let pipeline_handle = tokio::spawn(pipeline.run());
    // 2. Run the viewer on the main thread. This is a blocking call.
    run_egui_app_on_man_thread::<EguiAppExampleBuilder, EguiAppExample>(builder);
    // 3. Wait for the pipeline to finish.
    pipeline_handle.await.unwrap();
}
More examples
Hide additional examples
examples/one_dim_robot.rs (line 87)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
async fn run_robot_example() {
    let pipeline = Hollywood::configure(&mut |context| {
        let mut timer = Periodic::new_with_period(context, 0.1);
        let mut sim = Sim::from_prop_and_state(
            context,
            NullProp {},
            SimState {
                shutdown_time: 15.0,
                time: 0.0,
                seq: 0,
                true_robot: Robot {
                    position: -2.0,
                    velocity: 0.4,
                },
            },
        );
        let mut filter = Filter::from_prop_and_state(context, NullProp {}, FilterState::default());
        let mut filter_state_printer = Printer::<NamedFilterState>::from_prop_and_state(
            context,
            PrinterProp {
                topic: "filter state".to_owned(),
            },
            NullState::default(),
        );
        let mut truth_printer = Printer::<Stamped<Robot>>::from_prop_and_state(
            context,
            PrinterProp {
                topic: "truth".to_owned(),
            },
            NullState::default(),
        );

        let mut zip = Zip3::from_prop_and_state(context, NullProp {}, Zip3State::default());

        let mut draw = DrawActor::from_prop_and_state(context, NullProp {}, DrawState::default());

        timer
            .outbound
            .time_stamp
            .connect(context, &mut sim.inbound.time_stamp);

        sim.outbound
            .noisy_velocity
            .connect(context, &mut filter.inbound.noisy_velocity);
        sim.outbound
            .noisy_range
            .connect(context, &mut filter.inbound.noisy_range);
        sim.outbound.true_robot.connect_with_adapter(
            context,
            |x| ZipPair {
                key: x.seq,
                value: x,
            },
            &mut zip.inbound.item0,
        );
        sim.outbound.true_range.connect_with_adapter(
            context,
            |x| ZipPair {
                key: x.seq,
                value: x,
            },
            &mut zip.inbound.item1,
        );
        sim.outbound
            .true_robot
            .connect(context, &mut truth_printer.inbound.printable);

        sim.out_requests
            .ping_pong
            .connect(context, &mut filter.in_requests.ping_pong_request);
        context.register_cancel_requester(&mut sim.outbound.cancel_request);

        filter
            .outbound
            .updated_state
            .connect(context, &mut filter_state_printer.inbound.printable);
        filter.outbound.updated_state.connect_with_adapter(
            context,
            |x| ZipPair {
                key: x.state.seq,
                value: x,
            },
            &mut zip.inbound.item2,
        );

        zip.outbound
            .zipped
            .connect(context, &mut draw.inbound.zipped);
    });

    pipeline.print_flow_graph();

    let _pipeline = pipeline.run().await;
}
source

pub fn send_request(&self, msg: Request)

Sends a request message to the connected in-request channel of other actors.

Examples found in repository?
examples/egui.rs (line 85)
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
91
92
    fn on_message(
        self,
        _prop: &Self::Prop,
        state: &mut Self::State,
        outbound: &Self::OutboundHub,
        request: &Self::OutRequestHub,
    ) {
        match &self {
            ContentGeneratorInboundMessage::Tick(new_value) => {
                state.last_x = *new_value;

                let x = *new_value + state.offset;

                let s = Stream {
                    msg: PlotMessage::SinPlot((x, x.sin())),
                };
                outbound.plot_message.send(s);
                let c = Stream {
                    msg: PlotMessage::SinPlot((x, x.cos())),
                };
                outbound.plot_message.send(c);

                if x > 2.0 && x < 2.1 {
                    request.example_request.send_request("foo:".to_owned());
                }
            }
            ContentGeneratorInboundMessage::Reply(r) => {
                println!("Reply received {}", r.reply);
            }
        }
    }

Trait Implementations§

source§

impl<Request, Reply, M: IsInboundMessage> HasActivate for OutRequestChannel<Request, Reply, M>

source§

fn extract(&mut self) -> Self

Extract outbound/request channel and returns it.
source§

fn activate(&mut self)

Activates the outbound/request channel to be used.

Auto Trait Implementations§

§

impl<Request, Reply, M> Freeze for OutRequestChannel<Request, Reply, M>

§

impl<Request, Reply, M> !RefUnwindSafe for OutRequestChannel<Request, Reply, M>

§

impl<Request, Reply, M> Send for OutRequestChannel<Request, Reply, M>

§

impl<Request, Reply, M> Sync for OutRequestChannel<Request, Reply, M>

§

impl<Request, Reply, M> Unpin for OutRequestChannel<Request, Reply, M>

§

impl<Request, Reply, M> !UnwindSafe for OutRequestChannel<Request, Reply, M>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Downcast<T> for T

source§

fn downcast(&self) -> &T

source§

impl<T> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Upcast<T> for T

source§

fn upcast(&self) -> Option<&T>

source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> WasmNotSend for T
where T: Send,

source§

impl<T> WasmNotSendSync for T

source§

impl<T> WasmNotSync for T
where T: Sync,