Skip to content
Discussion options

You must be logged in to vote

You can do it. By one way of looking at it, it's kind of gross; with another way of looking at it, it is just a matter of adding the right trait implementations. Specifically, ToChildren.

Here's an example:

pub struct StepStruct {
    pub label: String,
    pub child: ViewFn,
}

struct Steps(Box<dyn FnOnce() -> Vec<StepStruct>>);

impl<F, C> ToChildren<F> for Steps
where
    F: FnOnce() -> C + Send + 'static,
    C: IntoSteps,
{
    #[inline]
    fn to_children(f: F) -> Self {
        Steps(Box::new(move || f().into_steps()))
    }
}

trait IntoSteps {
    fn into_steps(self) -> Vec<StepStruct>;
}

impl IntoSteps for () {
    fn into_steps(self) -> Vec<StepStruct> {
        vec![]
    }
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@seblyng
Comment options

Answer selected by seblyng
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants