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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
use crate as actify;
use actify_macros::actify;
use core::ops::RangeBounds;
use std::fmt::Debug;
trait ActorVec<T> {
fn push(&mut self, value: T);
fn is_empty(&self) -> bool;
fn drain<R>(&mut self, range: R) -> Vec<T>
where
R: RangeBounds<usize> + Send + Sync + 'static;
}
#[actify]
impl<T> ActorVec<T> for Vec<T>
where
T: Clone + Debug + Send + Sync + 'static,
{
/// Appends an element to the back of a collection.
///
/// # Examples
///
/// ```
/// # use tokio;
/// # #[tokio::test]
/// # async fn push_to_actor() {
/// let handle = actify::Handle::new(vec![1, 2]);
/// handle.push(100).await.unwrap();
/// assert_eq!(handle.get().await.unwrap(), vec![1, 2, 100]);
/// # }
/// ```
fn push(&mut self, value: T) {
self.push(value)
}
/// Returns `true` if the vector contains no elements.
///
/// # Examples
///
/// ```
/// # use tokio;
/// # use actify;
/// # #[tokio::test]
/// # async fn actor_vec_is_empty() {
/// let handle = Handle::new(Vec::<i32>::new());
/// assert!(handle.is_empty().await.unwrap());
/// # }
/// ```
fn is_empty(&self) -> bool {
self.is_empty()
}
/// Removes the complete range from the vector in bulk, and returns it as a new vector
///
/// # Examples
///
/// ```
/// # use tokio;
/// # #[tokio::test]
/// # async fn drain_actor() {
/// let handle = Handle::new(vec![1, 2]);
/// let res = handle.drain(..).await.unwrap();
/// assert_eq!(res, vec![1, 2]);
/// assert_eq!(handle.get().await.unwrap(), Vec::<i32>::new());
/// # }
/// ```
fn drain<R>(&mut self, range: R) -> Vec<T>
where
R: RangeBounds<usize> + Send + Sync + 'static,
{
self.drain(range).collect()
}
}