0
votes

I have the following struct that works fine:

pub struct Pattern {
    pub regex: &'static str,
    pub view: Fn (Request) -> Response,
}

But I'd like to change view to accept any type that implements Renderable (trait constraint). I was expecting to make it work this way:

pub struct Pattern {
    pub regex: &'static str,
    pub view: Fn <T: Renderable> (Request) -> T,
}

But no luck. Any ideas?

1

1 Answers

1
votes

You want to use a where clause on the struct (and any implementations for that struct):

trait A { fn moo(&self); }
struct S;

struct Pattern<T>
    where T: A
{
    view: Fn (T) -> S,
}

fn main() {}