Replies: 1 comment
-
Some points I miss
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Mostly for error handling. I need to respond a JSON serialized from different serde types in different code paths, which makes using something like
rocket::response::content::Json<R>
hard. I have the following thoughts.respond_to
method. Then I can just return differentResponse
in the different code paths. The downside is that it's a bit cumbersome to make use ofrocket::response::content::*
. In order to get the response from aResponder
implementation under that namespace, I need to call therespond_to
method on them and pass the request which needs to be passed all the way through the function called, while the method implementation may not use the request at all.rocket::response::content::*
. Instead, just manually set up content type, body, status code, etc. I think it can be helpful to have some methods to create the response like how therespond_to
methods of the types underrocket::response::content::*
do if the methods don't use the request parameter. I cannot find these methods in the standard library or in a third-party library. If someone else has done this, please let me know, otherwise, I might consider making one.Responder
for the dynamic-dispatch closure.Responder
cannot be turned into a trait object because therespond_to
method usesself
as the parameter. But Rust has a unique rule which allowsBox<dyn FnOnce(&'_ Request<'_>) -> Result<'_>>
. If the library can implementResponder
for this closure type, or a third-party library provides a wrapper of the closure that implementResponder
, then I can use it to unify eachResponder
. If someone else has done this, please let me know, otherwise, I might consider making one.Option
fields, including every possible field for each code path. Then I can use oneJson<R>
to represent all of them. I personally dislike this approach but if there are some good reasons to do this please tell me.Beta Was this translation helpful? Give feedback.
All reactions