This is a very common usecase, but I could not find any example of this (maybe I've looked in the wrong place).
In this situation, it feels natural to return a Vec for a JSON array and an Option where there could be or not a result (in this case, None would be a 404 error).
I solved the first case by using the newtype pattern:
In the case of optional return, if I understand well, I must return an Either type with either a 404 status or the wanted Foo, but I feel that this boilerplate is unnecessary.
Do you think that it is possible to implement Response:
I am doing a very small API with something like that:
This is a very common usecase, but I could not find any example of this (maybe I've looked in the wrong place).
In this situation, it feels natural to return a
Vec
for a JSON array and anOption
where there could be or not a result (in this case,None
would be a 404 error).I solved the first case by using the newtype pattern:
In the case of optional return, if I understand well, I must return an
Either
type with either a 404 status or the wantedFoo
, but I feel that this boilerplate is unnecessary.Do you think that it is possible to implement
Response
:Vec<T> where T: Response + Serialize
;Option<T> where T: Response
?