Skip to content

FormatInto object safety - or how can I make a collection of Token Streams? #30

@rrichardson

Description

@rrichardson

I am creating a custom HTTP handler class from a schema specification which has about 100 routes.

Because of reasons, my main dispatcher is basically a match from a usize to an function invocation:
e.g.

match index {
     0 => {  
         let input = FromRequest::from_request(req).await;
         let res = handler_0(input).await; 
         IntoResponse::into_response(res).await
      }, 
      1  =>   {  
         let input = FromRequest::from_request(req).await;
         let res = handler_0(input).await; 
         IntoResponse::into_response(res).await
      }, 
      N => {
          ... 
      }
}

I want to create a Vec<Box<dyn FormatInto<Rust>> of handlers and then iterate through them and create each match block.
However, I can't, because format_into takes self

It would be nice if there was an alternative to format_into that didn't consume self. Or maybe there is a better overall approach?

What is the recommended way to create a vector of token streams that I can inject into here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions