laralang 0.1.0

Localized routes for Laravel Rust: one route per language, translated paths, resources and hreflang alternates.
Documentation
use std::future::Future;

tokio::task_local! {
    static CURRENT: Current;
}

/// What the locale middleware knows about the request: whether the locale is resolved, and which
/// localized route matched.
#[derive(Debug, Clone, Default)]
pub(crate) struct Current {
    pub(crate) resolved: bool,
    pub(crate) route: Option<Matched>,
}

/// The localized route that matched the request.
#[derive(Debug, Clone)]
pub(crate) struct Matched {
    /// The full name, such as `es.profile`.
    pub(crate) name: Option<String>,
    /// The name without its locale, such as `profile`.
    pub(crate) base: Option<String>,
    /// The route's parameters, as the request carried them.
    pub(crate) params: Vec<(String, String)>,
}

pub(crate) fn get() -> Option<Current> {
    CURRENT.try_with(Clone::clone).ok()
}

pub(crate) async fn scope<F: Future>(current: Current, future: F) -> F::Output {
    CURRENT.scope(current, future).await
}