1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 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
use crate as actify;
use actify_macros::actify;
use std::fmt::Debug;
trait ActorOption<T> {
fn is_some(&self) -> bool;
fn is_none(&self) -> bool;
}
/// An implementation of the ActorOption extension trait for for the standard [`Option`].
/// This extension trait is made available on the handle through the actify macro.
/// Within the actor these methods are invoken, which in turn just extend the functionality provides by the std library.
///
/// [`Option`]: https://doc.rust-lang.org/std/option/enum.Option.html
#[actify]
impl<T> ActorOption<T> for Option<T>
where
T: Clone + Debug + Send + Sync + 'static,
{
/// Returns true if the option is a Some value.
///
/// # Examples
///
/// ```
/// # use tokio;
/// # use actify;
/// # #[tokio::test]
/// # async fn actor_option_is_some() {
/// let handle = Handle::new(Some(1));
/// assert_eq!(handle.is_some().await.unwrap(), true);
/// # }
/// ```
fn is_some(&self) -> bool {
self.is_some()
}
/// Returns true if the option is a None value.
///
/// # Examples
///
/// ```
/// # use tokio;
/// # use actify;
/// # #[tokio::test]
/// # async fn actor_option_is_none() {
/// let handle = Handle::new(Option::<i32>::None);
/// assert!(handle.is_none().await.unwrap());
/// # }
/// ```
fn is_none(&self) -> bool {
self.is_none()
}
}