pub struct TestLoopData { /* private fields */ }
Expand description
TestLoopData is the container for all data that is stored and accessed by the test loop.
TestLoopData is used to mainly register actors, which can be accessed using a handle during the execution of the TestLoop.
let mut data = TestLoopData::new(raw_pending_events_sender, shutting_down);
let actor = TestActor::new();
let adapter = LateBoundSender::new();
let sender: TestLoopSender<TestActor> = data.register_actor("client1", actor, Some(adapter));
// We can now send messages to the actor using the sender and adapter.
sender.send(TestMessage {});
adapter.send(TestMessage {});
We have the ability to register data of any type, and then access it using a handle. This is useful if we would like to have some arbitrary callback event in testloop to access this data.
let mut data = TestLoopData::new(raw_pending_events_sender, shutting_down);
let handle: TestLoopDataHandle<usize> = data.register_data(42);
assert_eq!(data.get(&handle), 42);
Note that the handler from one TestLoopData cannot be used to access data from another.
Implementations§
Source§impl TestLoopData
impl TestLoopData
Sourcepub fn register_data<T>(&mut self, data: T) -> TestLoopDataHandle<T>
pub fn register_data<T>(&mut self, data: T) -> TestLoopDataHandle<T>
Function to register data of any type in the TestLoopData. Returns a handler to the data that can be used to access the data later.
Sourcepub fn register_actor<A>(
&mut self,
identifier: &str,
actor: A,
adapter: Option<Arc<LateBoundSender<TestLoopSender<A>>>>,
) -> TestLoopSender<A>where
A: Actor + 'static,
pub fn register_actor<A>(
&mut self,
identifier: &str,
actor: A,
adapter: Option<Arc<LateBoundSender<TestLoopSender<A>>>>,
) -> TestLoopSender<A>where
A: Actor + 'static,
Function to register an actor in the TestLoopData.
We provide an identifier which is used to group events from the same client.
Usually the identifier is the account_id of the client.
This function additionally schedules the start event for the actor on testloop.
Returns a TestLoopSender
Sourcepub fn get<T>(&self, handle: &TestLoopDataHandle<T>) -> &T
pub fn get<T>(&self, handle: &TestLoopDataHandle<T>) -> &T
Function to get reference to the data stored in TestLoopData.
Sourcepub fn get_mut<T>(&mut self, handle: &TestLoopDataHandle<T>) -> &mut T
pub fn get_mut<T>(&mut self, handle: &TestLoopDataHandle<T>) -> &mut T
Function to get mutable reference to the data stored in TestLoopData.
Auto Trait Implementations§
impl Freeze for TestLoopData
impl !RefUnwindSafe for TestLoopData
impl !Send for TestLoopData
impl !Sync for TestLoopData
impl Unpin for TestLoopData
impl !UnwindSafe for TestLoopData
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
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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<A, B> IntoMultiSender<B> for Awhere
B: MultiSenderFrom<A>,
impl<A, B> IntoMultiSender<B> for Awhere
B: MultiSenderFrom<A>,
fn as_multi_sender(self: &Arc<A>) -> B
fn into_multi_sender(self) -> B
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request