Conditionally emit rocket::http_verb attr macros if lib/bin

This commit is contained in:
Devin Ragotzy 2020-07-25 23:08:00 -04:00 committed by timokoesters
parent b82fd02ee3
commit 42e0102a2a
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
8 changed files with 453 additions and 170 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,16 +1,18 @@
use crate::RumaResponse;
use http::StatusCode;
use log::error;
use rocket::{
response::{self, Responder},
Request,
};
use ruma::api::client::{
error::{Error as RumaError, ErrorKind},
r0::uiaa::{UiaaInfo, UiaaResponse},
};
use ruma::api::client::{error::ErrorKind, r0::uiaa::UiaaInfo};
use thiserror::Error;
#[cfg(feature = "conduit_bin")]
use {
crate::RumaResponse,
http::StatusCode,
rocket::{
response::{self, Responder},
Request,
},
ruma::api::client::{error::Error as RumaError, r0::uiaa::UiaaResponse},
};
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
@ -46,6 +48,7 @@ impl Error {
}
}
#[cfg(feature = "conduit_bin")]
impl<'r, 'o> Responder<'r, 'o> for Error
where
'o: 'r,

24
src/lib.rs Normal file
View file

@ -0,0 +1,24 @@
pub mod client_server;
mod database;
mod error;
mod pdu;
pub mod push_rules;
mod ruma_wrapper;
mod utils;
pub use database::Database;
pub use error::{Error, Result};
pub use pdu::PduEvent;
pub use ruma_wrapper::{ConduitResult, Ruma, RumaResponse};
use std::ops::Deref;
pub struct State<'r, T: Send + Sync + 'static>(&'r T);
impl<'r, T: Send + Sync + 'static> Deref for State<'r, T> {
type Target = T;
#[inline(always)]
fn deref(&self) -> &T {
self.0
}
}

View file

@ -13,6 +13,7 @@ mod utils;
pub use database::Database;
pub use error::{Error, Result};
pub use pdu::PduEvent;
pub use rocket::State;
pub use ruma_wrapper::{ConduitResult, Ruma, RumaResponse};
use rocket::{fairing::AdHoc, routes};

View file

@ -1,4 +1,3 @@
use js_int::uint;
use ruma::{
push::{
Action, ConditionalPushRule, ConditionalPushRuleInit, PatternedPushRule,
@ -185,7 +184,7 @@ pub fn encrypted_room_one_to_one_rule() -> ConditionalPushRule {
rule_id: ".m.rule.encrypted_room_one_to_one".to_owned(),
conditions: vec![
PushCondition::RoomMemberCount {
is: RoomMemberCountIs::from(uint!(2)..),
is: RoomMemberCountIs::from(2_u32.into()..),
},
PushCondition::EventMatch {
key: "type".to_owned(),
@ -208,7 +207,7 @@ pub fn room_one_to_one_rule() -> ConditionalPushRule {
rule_id: ".m.rule.room_one_to_one".to_owned(),
conditions: vec![
PushCondition::RoomMemberCount {
is: RoomMemberCountIs::from(uint!(2)..),
is: RoomMemberCountIs::from(2_u32.into()..),
},
PushCondition::EventMatch {
key: "type".to_owned(),

View file

@ -1,15 +1,24 @@
use crate::{utils, Error};
use log::warn;
use rocket::{
data::{Data, FromDataFuture, FromTransformedData, Transform, TransformFuture, Transformed},
http::Status,
response::{self, Responder},
Outcome::*,
Request, State,
use crate::Error;
use ruma::identifiers::{DeviceId, UserId};
use std::{convert::TryInto, ops::Deref};
#[cfg(feature = "conduit_bin")]
use {
crate::utils,
log::warn,
rocket::{
data::{
Data, FromDataFuture, FromTransformedData, Transform, TransformFuture, Transformed,
},
http::Status,
response::{self, Responder},
tokio::io::AsyncReadExt,
Outcome::*,
Request, State,
},
ruma::api::Endpoint,
std::io::Cursor,
};
use ruma::{api::Endpoint, DeviceId, UserId};
use std::{convert::TryInto, io::Cursor, ops::Deref};
use tokio::io::AsyncReadExt;
/// This struct converts rocket requests into ruma structs by converting them into http requests
/// first.
@ -20,6 +29,7 @@ pub struct Ruma<T> {
pub json_body: Option<Box<serde_json::value::RawValue>>, // This is None when body is not a valid string
}
#[cfg(feature = "conduit_bin")]
impl<'a, T: Endpoint> FromTransformedData<'a> for Ruma<T> {
type Error = (); // TODO: Better error handling
type Owned = Data;
@ -119,6 +129,7 @@ impl<T: TryInto<http::Response<Vec<u8>>>> From<T> for RumaResponse<T> {
}
}
#[cfg(feature = "conduit_bin")]
impl<'r, 'o, T> Responder<'r, 'o> for RumaResponse<T>
where
T: Send + TryInto<http::Response<Vec<u8>>>,