euv_core/style/sheet/trait.rs
1use super::*;
2
3/// Zero-cost type-directed property application trait for keyless `style!` declarations.
4pub trait StyleApply {
5 /// Mutates `style` directly in place without copying the full `Style` struct by value.
6 ///
7 /// # Arguments
8 ///
9 /// - `Self` - Strongly-typed style property value.
10 /// - `&mut Style` - Mutable style accumulator modified in place.
11 fn apply_in_place(self, style: &mut Style);
12
13 /// Initializes a fresh `Style` from this strongly-typed style property or returns `self` directly when already a `Style`.
14 ///
15 /// # Arguments
16 ///
17 /// - `Self` - Strongly-typed style property value or base `Style`.
18 ///
19 /// # Returns
20 ///
21 /// - `Style` - Initialized `Style` value.
22 #[must_use]
23 #[inline(always)]
24 fn into_base_style(self) -> Style
25 where
26 Self: Sized,
27 {
28 let mut style: Style = Style::default();
29 self.apply_in_place(&mut style);
30 style
31 }
32
33 /// Applies this strongly-typed style property onto `style` and returns the updated value.
34 ///
35 /// # Arguments
36 ///
37 /// - `Self` - Strongly-typed style property value.
38 /// - `Style` - Target style accumulator.
39 ///
40 /// # Returns
41 ///
42 /// - `Style` - Updated style with the property applied.
43 #[must_use]
44 #[inline(always)]
45 fn apply_to(self, mut style: Style) -> Style
46 where
47 Self: Sized,
48 {
49 self.apply_in_place(&mut style);
50 style
51 }
52}