//! Actor is an entity capable of receiving and processing messages.
//!
//! For details, see the [`Actor`] documentation.
use async_trait;
use crate::;
/// Action to be performed after `Actor::stopping` is called.
///
/// In this method, actor can decide whether it will indeed stop
/// or keep running.
/// Actor is an entity capable of receiving and processing messages.
///
/// Each actor runs in an associated [`Context`] object that is capable
/// of managing the message delivery and maintaing the actor state.
///
/// Minimal implementation of an actor doesn't require any methods on it
/// and can be used on (almost) any type as a marker.
///
/// However, optional methods for better control of the actor lifespan
/// are provided:
///
/// - `started` method is called once [`Context`] was launched and is about
/// to start processing incoming messages.
/// - `stopping` method is called after either [`Address::stop`] method was
/// executed, or all the [`Address`] objects connected to an actor were
/// dropped.
/// - `stopped` method is a notification signaling that the [`Context`] future
/// is finishing its execution and after this call `Actor` object will be
/// dropped.
///
/// ## Stopping
///
/// Actor can stop in the following scenarios:
///
/// - [`Address::stop`] method was invoked.
/// - Runtime in which [`Context`] is spawned was shutdown.
///
/// ## Prerequisites
///
/// As actors must be suitable for using in the multithreaded runtimes,
/// each type implementing `Actor` must be [`Send`], [`Sync`] and [`'static`][static_lt].
///
/// Additionally, it must implement [`Unpin`](std::marker::Unpin)
///
/// [static_lt]: https://doc.rust-lang.org/reference/types/trait-object.html#trait-object-lifetime-bounds
///
/// ## Extensions
///
/// When one of the runtime features is enabled in this crate, there is also an extension trait available:
/// [`RuntimeActorExt`], which provides more convenient interface for spawning actors, e.g. [`RuntimeActorExt::spawn`].
///
/// ## Examples
///
/// This example assumes that `messages` is used with `rt-tokio` feature enabled.
///
/// ```rust
/// # use messages::prelude::*;
///
/// struct Ping;
///
/// #[async_trait]
/// impl Actor for Ping {
/// async fn started(&mut self) {
/// println!("Actor was started");
/// }
///
/// async fn stopping(&mut self) -> ActorAction {
/// println!("Actor is stopping");
/// ActorAction::Stop
/// }
///
/// fn stopped(&mut self) {
/// println!("Actor is stopped");
/// }
/// }
///
/// #[tokio::main]
/// async fn main() {
/// let mut addr = Ping.spawn();
/// addr.stop().await;
/// addr.wait_for_stop().await;
/// }
/// ```
cfg_runtime!