Struct MatrixRequest

Source
pub struct MatrixRequest<'a, T, U = ClientApi> {
    pub meth: Method,
    pub endpoint: Cow<'a, str>,
    pub params: HashMap<Cow<'a, str>, Cow<'a, str>>,
    pub body: T,
    pub typ: U,
}
Expand description

A arbitrary request to an endpoint in the Matrix API.

To actually determine what URL is used for the request, two things are consulted: the request type, and the request endpoint. The request type specifies what Matrix API is being used (for example, the client-server API revision 0, under /_matrix/client/r0), while the endpoint determines what method is being called on that API.

This type has Super Cow Powers.

Fields§

§meth: Method

Request method (exported in the http module)

§endpoint: Cow<'a, str>

API endpoint (e.g. /sync)

§params: HashMap<Cow<'a, str>, Cow<'a, str>>

Query-string parameters.

§body: T

Request body (some type implementing Serialize).

If this is empty (serialises to {}), it will not be sent. Therefore, requests with no body should use () here.

§typ: U

Request type.

Implementations§

Source§

impl<'a, T, U> MatrixRequest<'a, T, U>
where T: Serialize, U: ApiType,

Source

pub fn new<S: Into<Cow<'a, str>>>( meth: Method, endpoint: S, body: T, typ: U, ) -> Self

Make a new MatrixRequest, specifying all possible options.

Source§

impl<'a> MatrixRequest<'a, ()>

Source

pub fn new_basic<S: Into<Cow<'a, str>>>(meth: Method, endpoint: S) -> Self

Makes a MatrixRequest with the following defaults:

  • meth and endpoint specified
  • params set to an empty hashmap
  • body set to ()
  • typ set to apis::r0::ClientApi
Source§

impl<'a, 'b, 'c> MatrixRequest<'a, HashMap<Cow<'b, str>, Cow<'c, str>>>

Source

pub fn new_with_body<S, T, U, V>(meth: Method, endpoint: S, body: V) -> Self
where S: Into<Cow<'a, str>>, T: Into<Cow<'b, str>>, U: Into<Cow<'c, str>>, V: IntoIterator<Item = (T, U)>,

Makes a MatrixRequest with the following defaults:

  • meth and endpoint specified
  • body converted from an iterator over (T, U) where T & U implement Into<Cow<str>>
  • params set to an empty hashmap
  • typ set to apis::r0::ClientApi
Source§

impl<'a, T> MatrixRequest<'a, T>
where T: Serialize,

Source

pub fn new_with_body_ser<S>(meth: Method, endpoint: S, body: T) -> Self
where S: Into<Cow<'a, str>>,

Like new_with_body, but takes a serializable object for body.

Source§

impl<'a, T, U> MatrixRequest<'a, T, U>
where T: Serialize, U: ApiType,

Source

pub fn make_request<C>(&self, client: &C) -> MatrixResult<Request<Vec<u8>>>

Make this MatrixRequest into a HTTP request.

Source

pub fn send<C, R>( &self, mxc: &mut C, ) -> impl Future<Item = R, Error = MatrixError> + 'static
where R: DeserializeOwned + 'static, C: MatrixRequestable,

Sends this request to a Matrix homeserver, expecting a deserializable R return type.

A helpful mix of make_hyper() and MatrixClient::send_request().

Source

pub fn discarding_send<'x, 'y, C>( &'x self, mxc: &'y mut C, ) -> impl Future<Item = (), Error = MatrixError> + 'static

Like send(), but uses MatrixClient::send_discarding_request().

Auto Trait Implementations§

§

impl<'a, T, U> Freeze for MatrixRequest<'a, T, U>
where T: Freeze, U: Freeze,

§

impl<'a, T, U> RefUnwindSafe for MatrixRequest<'a, T, U>

§

impl<'a, T, U> Send for MatrixRequest<'a, T, U>
where T: Send, U: Send,

§

impl<'a, T, U> Sync for MatrixRequest<'a, T, U>
where T: Sync, U: Sync,

§

impl<'a, T, U> Unpin for MatrixRequest<'a, T, U>
where T: Unpin, U: Unpin,

§

impl<'a, T, U> UnwindSafe for MatrixRequest<'a, T, U>
where T: UnwindSafe, U: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.