Skip to content

Commit 8a94633

Browse files
vorporealwarp-agent
andcommitted
Replace per-setting settings-event macro expansion with shared generic registration
The register_settings_events! macro expanded a full registration function for every setting. Move that body into settings::registration, where it is generic over only the settings group and value types, so settings that share those types share one compiled instantiation. The macro now only builds a SettingCallbacks struct of function pointers at its expansion site, which keeps the method resolution of the old expanded code. Emit change events through the new SettingChangeEvent trait so define_setting! and implement_setting_for_enum! generate one concat_idents! block per setting instead of four. Co-Authored-By: Warp <agent@warp.dev>
1 parent dc10778 commit 8a94633

3 files changed

Lines changed: 310 additions & 181 deletions

File tree

crates/settings/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#[macro_use]
22
pub mod macros;
33
pub mod manager;
4+
pub mod registration;
45
pub mod schema;
56

67
// Re-export commonly used types and traits
@@ -640,6 +641,17 @@ pub trait Setting {
640641
fn is_value_explicitly_set(&self) -> bool;
641642
}
642643

644+
/// A trait that maps a setting to the change event of its settings group.
645+
///
646+
/// The setting macros implement this trait for each setting they define. This
647+
/// lets the shared `Setting` implementations construct the correct group event
648+
/// variant without expanding per-setting event code at each emit site.
649+
pub trait SettingChangeEvent: Setting {
650+
/// Returns the group event that reports a change to this setting for the
651+
/// given reason.
652+
fn change_event(reason: ChangeEventReason) -> <Self::Group as Entity>::Event;
653+
}
654+
643655
/// Shared persistence operations for typed settings backed by secure storage.
644656
///
645657
/// Implementors remain responsible for routing their [`Setting`] lifecycle

0 commit comments

Comments
 (0)