Skip to main content

Module extensions

Module extensions 

Source
Expand description

ThemeExtensions: the no-lock-in typed extension slot crate::theme::Theme carries (a Flutter ThemeExtension analog).

Theme is a fixed 9(+1)-field struct — every widget in this repo reads a named field, and that stays true. But a third-party design system (or an app) that wants to carry its own token types alongside the built-in ones (without forking frust-theme to add a field Theme doesn’t otherwise need) has nowhere to put them. ThemeExtensions is that seam: a small persistent type-map keyed by TypeId, Arc-backed so a Theme clone (required at both delivery paths — the process-global set_app_theme Mutex slot and the reactive provide_context copy, see docs/ARCHITECTURE.md’s Theme delivery) stays cheap regardless of how many extension types are attached.

StatusPalette is the first consumer — see that module.

§Examples

use frust_theme::Theme;

// A third-party (or app-local) extension type — nothing `frust-theme`
// needs to know about ahead of time.
#[derive(Debug, Clone, PartialEq)]
struct BrandTokens {
    logo_glow: bool,
}

let mut theme = Theme::neutral();
theme.extensions.insert(BrandTokens { logo_glow: true });

let tokens = theme.extension::<BrandTokens>().expect("inserted above");
assert!(tokens.logo_glow);

// A type that was never inserted comes back `None`, never a panic.
#[derive(Debug)]
struct NeverInserted;
assert!(theme.extension::<NeverInserted>().is_none());

Structs§

ThemeExtensions
A persistent, typed extension map: any 'static + Send + Sync type can be attached once (a later insert of the same type replaces it) and recovered by type via get.