♻️ (config): Ajustes con #[settings] al arrancar
- Nuevo atributo `#[settings]`: valores por defecto en los campos (tipos comprobados al compilar y documentados); claves desconocidas y valores no válidos rechazados. Sustituye a `include_config!`, que se elimina. - `LazySettings<T>::new()` declara los ajustes de una sección, y `Extension::settings()` los carga al arrancar, en orden; un error de configuración o una sección reclamada dos veces detiene el arranque. - Aviso de secciones que no corresponden a ninguna extensión. - Bootsier: [dev] bootsier_static_dir pasa a [bootsier] static_dir.
This commit is contained in:
parent
8a7a827259
commit
728a5c83dc
32 changed files with 918 additions and 488 deletions
25
tests/config_duplicate_section.rs
Normal file
25
tests/config_duplicate_section.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
// Settings that claim `[app]`, a section that already belongs to the global settings.
|
||||
#[settings(section = "app")]
|
||||
pub struct ClashingSettings {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
static SETTINGS: LazySettings<ClashingSettings> = LazySettings::new();
|
||||
|
||||
// `EXTENSIONS` is a global `OnceLock`, so this test needs its own test binary.
|
||||
struct ClashingExtension;
|
||||
|
||||
#[async_trait]
|
||||
impl Extension for ClashingExtension {
|
||||
fn settings(&self) -> Option<&'static dyn LoadSettings> {
|
||||
Some(&SETTINGS)
|
||||
}
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
#[should_panic(expected = "Settings section [app] is claimed by more than one extension")]
|
||||
async fn a_section_claimed_twice_stops_the_startup() {
|
||||
let _ = Application::prepare(&ClashingExtension).await;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue