css_in_rs/
backend.rs

1#[cfg(feature = "web-sys")]
2pub mod web;
3
4use crate::Theme;
5
6pub type CssGeneratorFn<T> = fn(&T, &mut String, &mut u64) -> ();
7
8/// css-in-rs is backend agnostic. The default backend is based on web_sys,
9/// but other backends are possible (i.e. just insert css into a string, for
10/// example for server side rendering).
11pub trait Backend<T: Theme>: 'static {
12    /// Replaces all styles managed by this backend by the given CSS string
13    fn replace_all(&mut self, css: String);
14
15    /// Runs a given css generator and add the generated styles. The `generator`
16    /// function is expected to append new rules to the given `String`. It may
17    /// be empty, in which case the new style is to be returned. Alternatively,
18    /// the backend may choose to put in all existing rules, in which case the
19    /// new rules are to be appended.
20    fn run_css_generator(&mut self, generator: CssGeneratorFn<T>, theme: &T, counter: &mut u64);
21}