pub struct Client<C>(/* private fields */);
client-ext-client-api
only.Expand description
A client for the Matrix client-server API.
Implementations§
source§impl Client<()>
impl Client<()>
sourcepub fn builder() -> ClientBuilder
Available on crate feature client
only.
pub fn builder() -> ClientBuilder
client
only.Creates a new client builder.
source§impl<C> Client<C>
impl<C> Client<C>
sourcepub fn access_token(&self) -> Option<String>
Available on crate feature client
only.
pub fn access_token(&self) -> Option<String>
client
only.Get a copy of the current access_token
, if any.
Useful for serializing and persisting the session to be restored later.
source§impl<C> Client<C>where
C: HttpClient,
impl<C> Client<C>where
C: HttpClient,
sourcepub async fn send_request<R>(
&self,
request: R,
) -> Result<<R as OutgoingRequest>::IncomingResponse, Error<<C as HttpClient>::Error, <R as OutgoingRequest>::EndpointError>>where
R: OutgoingRequest,
Available on crate feature client
only.
pub async fn send_request<R>(
&self,
request: R,
) -> Result<<R as OutgoingRequest>::IncomingResponse, Error<<C as HttpClient>::Error, <R as OutgoingRequest>::EndpointError>>where
R: OutgoingRequest,
client
only.Makes a request to a Matrix API endpoint.
sourcepub async fn send_customized_request<R, F>(
&self,
request: R,
customize: F,
) -> Result<<R as OutgoingRequest>::IncomingResponse, Error<<C as HttpClient>::Error, <R as OutgoingRequest>::EndpointError>>where
R: OutgoingRequest,
F: FnOnce(&mut Request<<C as HttpClient>::RequestBody>) -> Result<(), Error<<C as HttpClient>::Error, <R as OutgoingRequest>::EndpointError>>,
Available on crate feature client
only.
pub async fn send_customized_request<R, F>(
&self,
request: R,
customize: F,
) -> Result<<R as OutgoingRequest>::IncomingResponse, Error<<C as HttpClient>::Error, <R as OutgoingRequest>::EndpointError>>where
R: OutgoingRequest,
F: FnOnce(&mut Request<<C as HttpClient>::RequestBody>) -> Result<(), Error<<C as HttpClient>::Error, <R as OutgoingRequest>::EndpointError>>,
client
only.Makes a request to a Matrix API endpoint including additional URL parameters.
sourcepub async fn send_request_as<R>(
&self,
user_id: &UserId,
request: R,
) -> Result<<R as OutgoingRequest>::IncomingResponse, Error<<C as HttpClient>::Error, <R as OutgoingRequest>::EndpointError>>where
R: OutgoingRequest,
Available on crate feature client
only.
pub async fn send_request_as<R>(
&self,
user_id: &UserId,
request: R,
) -> Result<<R as OutgoingRequest>::IncomingResponse, Error<<C as HttpClient>::Error, <R as OutgoingRequest>::EndpointError>>where
R: OutgoingRequest,
client
only.Makes a request to a Matrix API endpoint as a virtual user.
This method is meant to be used by application services when interacting with the client-server API.
sourcepub async fn log_in(
&self,
user: &str,
password: &str,
device_id: Option<&DeviceId>,
initial_device_display_name: Option<&str>,
) -> Result<Response, Error<<C as HttpClient>::Error, Error>>
Available on crate feature client
only.
pub async fn log_in( &self, user: &str, password: &str, device_id: Option<&DeviceId>, initial_device_display_name: Option<&str>, ) -> Result<Response, Error<<C as HttpClient>::Error, Error>>
client
only.Log in with a username and password.
In contrast to send_request
, this method stores the access token
returned by the endpoint in this client, in addition to returning it.
sourcepub async fn register_guest(
&self,
) -> Result<Response, Error<<C as HttpClient>::Error, UiaaResponse>>
Available on crate feature client
only.
pub async fn register_guest( &self, ) -> Result<Response, Error<<C as HttpClient>::Error, UiaaResponse>>
client
only.Register as a guest.
In contrast to send_request
, this method stores the access token
returned by the endpoint in this client, in addition to returning it.
sourcepub async fn register_user(
&self,
username: Option<&str>,
password: &str,
) -> Result<Response, Error<<C as HttpClient>::Error, UiaaResponse>>
Available on crate feature client
only.
pub async fn register_user( &self, username: Option<&str>, password: &str, ) -> Result<Response, Error<<C as HttpClient>::Error, UiaaResponse>>
client
only.Register as a new user on this server.
In contrast to send_request
, this method stores the access token
returned by the endpoint in this client, in addition to returning it.
The username is the local part of the returned user_id. If it is omitted from this request, the server will generate one.
sourcepub fn sync(
&self,
filter: Option<Filter>,
since: String,
set_presence: PresenceState,
timeout: Option<Duration>,
) -> impl Stream<Item = Result<Response, Error<<C as HttpClient>::Error, Error>>>
Available on crate feature client
only.
pub fn sync( &self, filter: Option<Filter>, since: String, set_presence: PresenceState, timeout: Option<Duration>, ) -> impl Stream<Item = Result<Response, Error<<C as HttpClient>::Error, Error>>>
client
only.Convenience method that represents repeated calls to the sync_events endpoint as a stream.
§Example:
use std::time::Duration;
let mut sync_stream = Box::pin(client.sync(
None,
next_batch_token,
PresenceState::Online,
Some(Duration::from_secs(30)),
));
while let Some(response) = sync_stream.try_next().await? {
// Do something with the data in the response...
}
Trait Implementations§
Auto Trait Implementations§
impl<C> Freeze for Client<C>
impl<C> RefUnwindSafe for Client<C>where
C: RefUnwindSafe,
impl<C> Send for Client<C>
impl<C> Sync for Client<C>
impl<C> Unpin for Client<C>
impl<C> UnwindSafe for Client<C>where
C: RefUnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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