Runtime

Struct Runtime 

Source
pub struct Runtime { /* private fields */ }
Expand description

The main component of acril_rt - the runtime. It stores the running services and handles their lifecycle and messages sent to them.

Implementations§

Source§

impl Runtime

Source

pub fn new() -> Self

Examples found in repository?
examples/ping.rs (line 94)
89async fn main() {
90    // make sure the runtime can spawn !Send tasks
91    let local_set = tokio::task::LocalSet::new();
92    let _guard = local_set.enter();
93
94    let runtime = acril_rt::Runtime::new();
95
96    local_set.run_until(async move {
97        #[cfg(debug_assertions)]
98        let printer = runtime.spawn(Printer::ToStdout).await;
99        #[cfg(not(debug_assertions))]
100        let printer = runtime.spawn(Printer::ToString(String::new())).await;
101        let pinger = runtime.spawn(Pinger { count: 0 }).await;
102
103        printer.send("Liftoff!".to_string()).await.unwrap();
104
105        for i in 0..10000 {
106            let pong = pinger.send(Ping).await.unwrap();
107
108            // i is 0-based and pong is 1-based because the pinger increments before returning
109            assert_eq!(pong.0, i + 1);
110
111            printer.send(format!("pong #{}", pong.0)).await.unwrap();
112        }
113
114        assert_eq!(pinger.send(GetOutput).await.unwrap(), 10000);
115        #[cfg(not(debug_assertions))]
116        // assert that the output is Ok(Some(non_empty_string))
117        assert!(!printer.send(GetOutput).await.unwrap().unwrap().is_empty());
118
119        printer.send("We're done!".to_string()).await.unwrap();
120    }).await;
121}
Source

pub fn new_in(arbiter: &ArbiterHandle) -> Self

Source

pub async fn spawn<S: Service<Context = Context<S>> + Send + Sync + 'static>( &self, service: S, ) -> Addr<S>

Examples found in repository?
examples/ping.rs (line 98)
89async fn main() {
90    // make sure the runtime can spawn !Send tasks
91    let local_set = tokio::task::LocalSet::new();
92    let _guard = local_set.enter();
93
94    let runtime = acril_rt::Runtime::new();
95
96    local_set.run_until(async move {
97        #[cfg(debug_assertions)]
98        let printer = runtime.spawn(Printer::ToStdout).await;
99        #[cfg(not(debug_assertions))]
100        let printer = runtime.spawn(Printer::ToString(String::new())).await;
101        let pinger = runtime.spawn(Pinger { count: 0 }).await;
102
103        printer.send("Liftoff!".to_string()).await.unwrap();
104
105        for i in 0..10000 {
106            let pong = pinger.send(Ping).await.unwrap();
107
108            // i is 0-based and pong is 1-based because the pinger increments before returning
109            assert_eq!(pong.0, i + 1);
110
111            printer.send(format!("pong #{}", pong.0)).await.unwrap();
112        }
113
114        assert_eq!(pinger.send(GetOutput).await.unwrap(), 10000);
115        #[cfg(not(debug_assertions))]
116        // assert that the output is Ok(Some(non_empty_string))
117        assert!(!printer.send(GetOutput).await.unwrap().unwrap().is_empty());
118
119        printer.send("We're done!".to_string()).await.unwrap();
120    }).await;
121}

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.