How to declare a generic structure that accepts any function?

Viewed 52

I need to implement a simple FSM with memory:

pub struct Fsm<TFunc> {
    memory: Vec<TFunc>
}

However in my sample the TFunc is any type, how to bound it to callable or function? In short, to I could use only functions as a type.

Is it possible in rust?

ADDED
To be clear I need the next behaviour:

fsm1 = Fsm::<Fn(usize)->usize>::new(); // Ok
fsm2 = Fsm::<Fn(usize, String)>::new(); // Ok
fsm3 = Fsm::<String>::new(); // Failed! It's not a function
0 Answers
Related