Bump dependencies and fixes

This commit is contained in:
timokoesters 2020-04-23 14:27:50 +02:00
parent 873d191569
commit 120b6f4b95
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
7 changed files with 67 additions and 90 deletions

View file

@ -7,12 +7,11 @@ use rocket::{
Request, State,
};
use ruma_api::{
error::{FromHttpRequestError, FromHttpResponseError},
Endpoint, Outgoing,
Endpoint
};
use ruma_identifiers::UserId;
use std::{
convert::{TryFrom, TryInto},
convert::{TryInto},
io::Cursor,
ops::Deref,
};
@ -22,21 +21,13 @@ const MESSAGE_LIMIT: u64 = 65535;
/// This struct converts rocket requests into ruma structs by converting them into http requests
/// first.
pub struct Ruma<T: Outgoing> {
body: T::Incoming,
pub struct Ruma<T> {
body: T,
pub user_id: Option<UserId>,
pub json_body: serde_json::Value,
}
impl<'a, T: Endpoint> FromData<'a> for Ruma<T>
where
// We need to duplicate Endpoint's where clauses because the compiler is not smart enough yet.
// See https://github.com/rust-lang/rust/issues/54149
<T as Outgoing>::Incoming: TryFrom<http::Request<Vec<u8>>, Error = FromHttpRequestError>,
<T::Response as Outgoing>::Incoming: TryFrom<
http::Response<Vec<u8>>,
Error = FromHttpResponseError<<T as Endpoint>::ResponseError>,
>,
{
type Error = (); // TODO: Better error handling
type Owned = Data;
@ -95,7 +86,7 @@ where
let http_request = http_request.body(body.clone()).unwrap();
log::info!("{:?}", http_request);
match T::Incoming::try_from(http_request) {
match T::try_from(http_request) {
Ok(t) => Success(Ruma {
body: t,
user_id,
@ -115,8 +106,8 @@ where
}
}
impl<T: Outgoing> Deref for Ruma<T> {
type Target = T::Incoming;
impl<T> Deref for Ruma<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.body