rok-core 0.6.0

Core primitives for the rok ecosystem — errors, crypto, i18n, config, DI, and more
Documentation
use std::future::Future;
use std::pin::Pin;

use crate::app::AppRef;
use crate::error::RokError;

/// A service provider registers services, config, and bindings into the
/// application container.
///
/// Analogous to Laravel service providers or AdonisJS providers.
///
/// # Built-in providers
///
/// | Crate | Provider |
/// |-------|----------|
/// | `rok-orm` | `OrmServiceProvider` |
/// | `rok-auth` | `AuthServiceProvider` |
/// | `rok-mail` | `MailServiceProvider` |
/// | `rok-cache` | `CacheServiceProvider` |
/// | `rok-queue` | `QueueServiceProvider` |
/// | `rok-storage` | `StorageServiceProvider` |
/// | `rok-notification` | `NotificationServiceProvider` |
pub trait ServiceProvider: Send + Sync {
    /// Human-readable provider name.
    fn name(&self) -> &'static str;

    /// Types this provider registers in the container.
    fn provides(&self) -> Vec<&'static str> {
        vec![]
    }

    /// Register services and bindings.
    fn register(
        &self,
        app: &mut AppRef,
    ) -> Pin<Box<dyn Future<Output = Result<(), RokError>> + Send + '_>>;

    /// Boot after all providers are registered.
    fn boot(
        &self,
        _app: &crate::app::App,
    ) -> Pin<Box<dyn Future<Output = Result<(), RokError>> + Send + '_>> {
        Box::pin(async { Ok(()) })
    }
}