Fold with different types using Warp

Hi, I'm working with Warp, I'm trying to make a Filter from an array of Structs to make a chainable Ors (i.e. route_1.or(route_2).or(route_3)) this way:

let routes = server_object.routes.iter().fold(None, |res: Option<dyn Filter>, (origin_route, destination_route)| {
    let new_route = warp::path(origin_route).and(warp::fs::file(destination_route));
    match res {
        Some(route) => Some(route.or(new_route)),
        None => new_route,
    }
});

But It says that I must specify the size of the Option as the first iteration, when res is None it returns an And struct but in the next iterations it returns an Or. I tried setting the type to:

Option<Box<dyn Filter<Extract = Reply, Error = Reject, Future = Rejection> + Clone + Send + Sync + 'static>>

Which is the type that expects the function serve, but the compiler says that

the trait warp::reject::Reject cannot be made into an object

I don't know how to continue. I just need to chain Or structs, maybe I'm complicating thing unnecesarily. Any kind of help would be really appreciated.

Thanks in advance

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.