summaryrefslogtreecommitdiff
path: root/mingling_core/src/program/setup.rs
blob: 7b534f31e3bf5133df29cd88d7735b9e4721fa62 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use std::fmt::Display;

use crate::{ProgramCollect, program::Program};

mod basic;
pub use basic::*;

#[cfg(feature = "general_renderer")]
mod general_renderer;
#[cfg(feature = "general_renderer")]
pub use general_renderer::*;

pub trait ProgramSetup<C, G>
where
    C: ProgramCollect,
    G: Display,
{
    fn setup(&mut self, program: &mut Program<C, G>);
}

impl<C, G> Program<C, G>
where
    C: ProgramCollect,
    G: Display,
{
    /// Load and execute init logic
    pub fn with_setup<S: ProgramSetup<C, G> + 'static>(&mut self, mut setup: S) -> S {
        S::setup(&mut setup, self);
        setup
    }
}