Re:Rust for C++ programmers – part 3: primitive types and op...
by mercurial on Wednesday April 23, 2014 @04:35AM
(#7632849)
Personally, I'd be inclined to have the context separate from the request, since they're really two different things. Also, you could introduce a FromRequest trait (trivially implemented by Request, returning self) to allow the user to build structures directly from a request (and its converse ToResponse), giving your function a signature of:
This would remove a lot of boilerplate for well-behaved applications. You'll also need a notion of middleware, which I guess would take a Request and return either a ToResponse or a request (eg, an authentication handler ought to return the response immediately in case of authentication failure), and similarly on the way out, something taking a Response and returning a Response.
[ Parent
| on HN ]
Re:Rust for C++ programmers – part 3: primitive types and op...
by mercurial on Wednesday April 23, 2014 @04:55AM
(#7632911)
Ah, obviously this wouldn't work, from_request would need to return Self and not a reference for it work, which means some overhead in the case of Request, since you'd have to clone it.