You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using actix to render html pages and I am currently trying to share the same base template across pages (especially for head tag)
So I have 2 structures: Layout and LayoutExtractor. The first holds data and the second only contains a Rc<RefCell<Layout>>. Then LayoutExtractor implements FromRequest to get the layout from request extensions:
#[derive(Default)]pubstructLayout{pubtitle:String,}pubstructLayoutExtractor(pubRc<RefCell<Layout>>);implFromRequestforLayoutExtractor{typeError = Error;typeFuture = Ready<Result<Self,Self::Error>>;fnfrom_request(request:&HttpRequest, _:&mutPayload) -> Self::Future{let layout = request
.extensions().get::<Rc<RefCell<Layout>>>().expect("Layout not inserted by middleware").clone();ready(Ok(LayoutExtractor(layout)))}}
Then I have 2 other structures for a middleware. LayoutMiddleware with exactly the same Transform implementation of the doc and LayoutMiddlewareService implementing Service. For this one I first add the Layout in request extensions, then call the service. And the hell comes just after: I retrieve the layout from the service response and use it to render my mustache template. Until this point all is good (almost). My problem is just after, I want to replace the response body with my newly rendered one, so I use map_body but I get a compilation error -> expected 'Result<ServiceResponse<B>, Error>', found 'Result<ServiceResponse<String>, _>' (ideally I will also want to pass the previous body to my renderer in order to include it)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Hi!
I'm using actix to render html pages and I am currently trying to share the same base template across pages (especially for head tag)
So I have 2 structures: Layout and LayoutExtractor. The first holds data and the second only contains a
Rc<RefCell<Layout>>. Then LayoutExtractor implements FromRequest to get the layout from request extensions:Then I have 2 other structures for a middleware. LayoutMiddleware with exactly the same Transform implementation of the doc and LayoutMiddlewareService implementing Service. For this one I first add the Layout in request extensions, then call the service. And the hell comes just after: I retrieve the layout from the service response and use it to render my mustache template. Until this point all is good (almost). My problem is just after, I want to replace the response body with my newly rendered one, so I use map_body but I get a compilation error ->
expected 'Result<ServiceResponse<B>, Error>', found 'Result<ServiceResponse<String>, _>'(ideally I will also want to pass the previous body to my renderer in order to include it)I have searched for discussion here, on stack-overflow and asked AI but found no viable answer. Am I totally wrong on my architecture?
The handler looks like this:
All reactions