act_zero/runtimes/
panic.rs

1//! Dummy runtime implementation which panics on use.
2//!
3//! This is used when no default runtime is enabled, and allows
4//! libraries to be built against this crate that *use* features
5//! requiring a runtime, but remaining runtime-agnostic.
6//!
7//! Binary crates should enable a specific default runtime, or
8//! enable the `default-disabled` feature to ensure this runtime
9//! is not used.
10
11use std::time::Instant;
12
13use futures::future::Pending;
14use futures::task::{Spawn, SpawnError};
15
16use crate::{timer, Actor, Addr};
17
18/// Type representing the dummy runtime.
19#[derive(Debug, Copy, Clone, Default)]
20pub struct Runtime;
21
22/// Alias for a dummy timer. This type can be default-constructed.
23/// Will always panic on use.
24pub type Timer = timer::Timer<Runtime>;
25
26/// Spawn an actor onto the dummy runtime.
27/// Will always panic.
28pub fn spawn_actor<T: Actor>(actor: T) -> Addr<T> {
29    Addr::new(&Runtime, actor).unwrap()
30}
31
32impl Spawn for Runtime {
33    fn spawn_obj(
34        &self,
35        _future: futures::future::FutureObj<'static, ()>,
36    ) -> Result<(), SpawnError> {
37        panic!("No default runtime selected")
38    }
39}
40
41impl timer::SupportsTimers for Runtime {
42    type Delay = Pending<()>;
43    fn delay(&self, _deadline: Instant) -> Self::Delay {
44        panic!("No default runtime selected")
45    }
46}