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
76
77
78
79
80
81
82
83
84
85
//! 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 use *;
pub use ;
pub use ;
/// 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!();
/// ```
pub use feature_table as table;
pub use FeatureServiceProvider;