laravel-rust 0.1.0

Laravel for Rust: a full-stack Rust web framework, inspired by PHP Laravel
Documentation
//! Feature flags let you ship code before everyone sees it, such as a new API that staff get
//! first, then one customer in a hundred.
//!
//! A feature is a function marked [`#[flag]`](macro@flag). It decides the feature's first value
//! for a scope, such as a user, a team, or the whole application. The store keeps that value, so
//! later checks read it back instead of running the function again:
//!
//! ```no_run,standalone_crate
//! use laravel::auth::Authenticated;
//! use laravel::feature::flag;
//! use laravel::lottery::Lottery;
//! use laravel::prelude::*;
//!
//! # #[derive(Clone, laravel::auth::Authenticatable)]
//! # pub struct User {
//! #     id: i64,
//! #     is_staff: bool,
//! #     password: Option<laravel::hash::PasswordHash>,
//! #     remember_token: Option<laravel::auth::RememberToken>,
//! # }
//! /// Staff get the new API, then one customer in a hundred.
//! #[flag]
//! pub fn new_api(user: &User) -> bool {
//!     user.is_staff || Lottery::odds(1, 100).draw()
//! }
//!
//! async fn servers(Authenticated(user): Authenticated<User>) -> laravel::Result<&'static str> {
//!     Ok(if user.features().active(new_api).await? { "new" } else { "legacy" })
//! }
//! ```
//!
//! Every [`Authenticatable`](crate::auth::Authenticatable) user has features through
//! [`HasFeatures`], and other scopes, such as teams, implement it. The free functions, such as
//! [`active`], check application-wide features, and [`guest`] checks features for a visitor who
//! isn't logged in.
//! [`RequireFeature`] guards a route, and [`ShareFeatures`] shares a user's features
//! with templates. In tests, [`fake()`] and [`fake_using`] pin a feature's value.
//!
//! The store files a user's values under the type's name and the user's ID, as `User|42`, so
//! renaming the user type loses its stored values. Within one request, command, or
//! [`Application::scope`](crate::Application::scope), every check of a feature for one scope sees
//! the same value: the first check reads the store, and later checks reuse it. When two requests
//! check a feature for the same scope for the first time at once, both run the function, and both
//! use the value the first one stored.
//!
//! The `database` store's table must exist before the first check, which otherwise fails with the
//! database's error. When `FEATURE_STORE` names a store no one registered, the application doesn't
//! boot.
//!
//! [`ShareFeatures`] checks every feature of the user's type on each request. In an HTTP test,
//! those checks may take the results of [`Lottery::fix`](crate::lottery::Lottery::fix) before
//! the feature you're testing, so prefer [`fake()`] when one feature's value matters.
//!
//! The [feature flags guide](https://github.com/laravel/rust-framework/blob/0.x/docs/feature-flags.md)
//! covers setup, the features table, and rollouts.

pub(crate) use laravel_feature::feature::*;
#[doc(hidden)]
pub use laravel_feature::feature::{
    __Activate, __ActivateWith, __ApplicationWide, __Flag, __For, __Global, __Outcome, __Registration, __RequestScope,
};
#[doc(inline)]
pub use laravel_feature::feature::{
    AnyFlag, Drivers, Everyone, Feature, FeatureStore, Features, Global, HasFeatures, OptionalFeatures, RequireFeature,
    ScopeKey, ShareFeatures, StoredValues, Value, activate, activate_with, active, all, deactivate, defined, everyone,
    fake, fake_using, find, flag, forget, guest, load, value,
};

/// Define a migration's `migrate` function to create the `database` feature store's table.
///
/// Put the macro alone in a migration file, and it creates the `features` table. To change the
/// table, replace the macro with the migration the
/// [feature flags guide](https://github.com/laravel/rust-framework/blob/0.x/docs/feature-flags.md#the-features-table)
/// shows, then edit it.
///
/// ```
/// // database/migrations/0001_01_01_000000_create_features_table.rs
/// laravel::feature::table!();
/// ```
#[cfg(feature = "database")]
pub use laravel_rust_database_macros::feature_table as table;

mod provider;

pub(crate) use self::provider::FeatureServiceProvider;