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>
impl<Request: Clone + Send + Sync + Debug + 'static, Reply: Clone + Send + Sync + Debug + 'static, M: IsInboundMessageNew<ReplyMessage<Reply>>> OutRequestChannel<Request, Reply, M>
sourcepub fn new(name: String, actor_name: &str, sender: &UnboundedSender<M>) -> Self
pub fn new(name: String, actor_name: &str, sender: &UnboundedSender<M>) -> Self
Creates a new out-request channel for the actor.
sourcepub fn connect<Me: IsInRequestMessageNew<RequestWithReplyChannel<Request, Reply>>>(
&mut self,
_ctx: &mut Hollywood,
inbound: &mut InRequestChannel<RequestWithReplyChannel<Request, Reply>, Me>
)
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
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;
}
sourcepub fn send_request(&self, msg: Request)
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>
impl<Request, Reply, M: IsInboundMessage> HasActivate for OutRequestChannel<Request, Reply, M>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
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>
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)
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)
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
impl<T> DowncastSync for T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.