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
Recently I found some arena libraries. I really like the idea behind it. I can use an arena through a request. I can alloc a data and shared the reference across many types as long as they are local to the request. I don't need to worry too much about lifetime, as all the data lives through the request.
This method works well for non-streaming body, I just need to write the handler like:
fn handler(request: Request) -> impl Responder {
let arena = Arena::new();
let result = do_my_work(&arena);
HttpResponse::Ok().json(result)
}
The problem is for the streaming body. Since the content of the stream might rely on the arena, the stream only lives no longer than the arena. If arena is created locally, the stream won't live long enough.
The type and the creation of the arena can be set by user (builtin is OK if it is not convinient), and it will be created before executing handler, dropped after the respond is fully transmitted to the client. In this case responding a stream becomes much easier.
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.
-
Recently I found some arena libraries. I really like the idea behind it. I can use an arena through a request. I can alloc a data and shared the reference across many types as long as they are local to the request. I don't need to worry too much about lifetime, as all the data lives through the request.
This method works well for non-streaming body, I just need to write the handler like:
The problem is for the streaming body. Since the content of the stream might rely on the arena, the stream only lives no longer than the arena. If arena is created locally, the stream won't live long enough.
So I hope I can write handler like this
The type and the creation of the arena can be set by user (builtin is OK if it is not convinient), and it will be created before executing handler, dropped after the respond is fully transmitted to the client. In this case responding a stream becomes much easier.
Beta Was this translation helpful? Give feedback.
All reactions