I have the following code
pub enum Endpoint<T> {
CreateRoom(T),
}
async fn request_impl<T, R>(end_point: Endpoint<T>) -> Result<R, ()>
where
R: DeserializeOwned,
{
let resp = http::Request::get("/path").send().await.unwrap();
resp.status() == 200;
resp.json().await.map_err(|_| ())
}
This code works, but we can see that when calling request_impl, we need to specify the returned type at the call site in order for it work. like let resp: usize = request_impl(Endpoint::CreateRoom(request)).await.unwrap()
Is there any trick i can do to the Endpoint enum (or some generic trick) so that the response typed is tied to the request typed during function definition? so that calling the function with a CreateRoomRequest will make sure that the function return a CreateRoomResponse