mirror of
https://github.com/rwf2/Rocket.git
synced 2024-12-26 12:22:36 +00:00
64e46b7107
Sentinels resolve a long-standing usability and functional correctness issue in Rocket: starting an application with guards and/or responders that depend on state that isn't available. The canonical example is the 'State' guard. Prior to this commit, an application with routes that queried unmanaged state via 'State' would fail at runtime. With this commit, the application refuses to launch with a detailed error message. The 'Sentinel' docs explains it as: A sentinel, automatically run on ignition, can trigger a launch abort should an instance fail to meet arbitrary conditions. Every type that appears in a mounted route's type signature is eligible to be a sentinel. Of these, those that implement 'Sentinel' have their 'abort()' method invoked automatically, immediately after ignition, once for each unique type. Sentinels inspect the finalized instance of 'Rocket' and can trigger a launch abort by returning 'true'. The following types are now sentinels: * 'contrib::databases::Connection' (any '#[database]' type) * 'contrib::templates::Metadata' * 'contrib::templates::Template' * 'core::State' The following are "specialized" sentinels, which allow sentinel discovery even through type aliases: * 'Option<T>', 'Debug<T>' if 'T: Sentinel' * 'Result<T, E>', 'Either<T, E>' if 'T: Sentinel', 'E: Sentinel' Closes #464. |
||
---|---|---|
.. | ||
src | ||
tests | ||
Cargo.toml |