matrix_sdk

Struct ClientBuilder

Source
pub struct ClientBuilder { /* private fields */ }
Expand description

Builder that allows creating and configuring various parts of a Client.

When setting the StateStore it is up to the user to open/connect the storage backend before client creation.

§Examples

use matrix_sdk::Client;
// To pass all the request through mitmproxy set the proxy and disable SSL
// verification

let client_builder = Client::builder()
    .proxy("http://localhost:8080")
    .disable_ssl_verification();

§Example for using a custom http client

Note: setting a custom http client will ignore user_agent, proxy, and disable_ssl_verification - you’d need to set these yourself if you want them.

use std::sync::Arc;

use matrix_sdk::Client;

// setting up a custom http client
let reqwest_builder = reqwest::ClientBuilder::new()
    .https_only(true)
    .no_proxy()
    .user_agent("MyApp/v3.0");

let client_builder =
    Client::builder().http_client(reqwest_builder.build()?);

Implementations§

Source§

impl ClientBuilder

Source

pub fn homeserver_url(self, url: impl AsRef<str>) -> Self

Set the homeserver URL to use.

The following methods are mutually exclusive: Self::homeserver_url, Self::server_name Self::insecure_server_name_no_tls, Self::server_name_or_homeserver_url. If you set more than one, then whatever was set last will be used.

Source

pub fn server_name(self, server_name: &ServerName) -> Self

Set the server name to discover the homeserver from.

We assume we can connect in HTTPS to that server. If that’s not the case, prefer using Self::insecure_server_name_no_tls.

The following methods are mutually exclusive: Self::homeserver_url, Self::server_name Self::insecure_server_name_no_tls, Self::server_name_or_homeserver_url. If you set more than one, then whatever was set last will be used.

Source

pub fn insecure_server_name_no_tls(self, server_name: &ServerName) -> Self

Set the server name to discover the homeserver from, assuming an HTTP (not secured) scheme. This also relaxes OIDC discovery checks to allow HTTP schemes.

The following methods are mutually exclusive: Self::homeserver_url, Self::server_name Self::insecure_server_name_no_tls, Self::server_name_or_homeserver_url. If you set more than one, then whatever was set last will be used.

Source

pub fn server_name_or_homeserver_url( self, server_name_or_url: impl AsRef<str>, ) -> Self

Set the server name to discover the homeserver from, falling back to using it as a homeserver URL if discovery fails. When falling back to a homeserver URL, a check is made to ensure that the server exists (unlike Self::homeserver_url, so you can guarantee that the client is ready to use.

The following methods are mutually exclusive: Self::homeserver_url, Self::server_name Self::insecure_server_name_no_tls, Self::server_name_or_homeserver_url. If you set more than one, then whatever was set last will be used.

Source

pub fn sliding_sync_version_builder( self, version_builder: SlidingSyncVersionBuilder, ) -> Self

Set sliding sync to a specific version.

Source

pub fn sqlite_store( self, path: impl AsRef<Path>, passphrase: Option<&str>, ) -> Self

Set up the store configuration for a SQLite store.

Source

pub fn sqlite_store_with_cache_path( self, path: impl AsRef<Path>, cache_path: impl AsRef<Path>, passphrase: Option<&str>, ) -> Self

Set up the store configuration for a SQLite store with cached data separated out from state/crypto data.

Source

pub fn store_config(self, store_config: StoreConfig) -> Self

Set up the store configuration.

The easiest way to get a StoreConfig is to use the make_store_config method from one of the store crates.

§Arguments
  • store_config - The configuration of the store.
§Examples
use matrix_sdk::{config::StoreConfig, Client};

let store_config =
    StoreConfig::new("cross-process-store-locks-holder-name".to_owned())
        .state_store(custom_state_store);
let client_builder = Client::builder().store_config(store_config);
Source

pub fn respect_login_well_known(self, value: bool) -> Self

Update the client’s homeserver URL with the discovery information present in the login response, if any.

Source

pub fn request_config(self, request_config: RequestConfig) -> Self

Set the default timeout, fail and retry behavior for all HTTP requests.

Source

pub fn proxy(self, proxy: impl AsRef<str>) -> Self

Set the proxy through which all the HTTP requests should go.

Note, only HTTP proxies are supported.

§Arguments
  • proxy - The HTTP URL of the proxy.
§Examples
use matrix_sdk::Client;

let client_config = Client::builder().proxy("http://localhost:8080");
Source

pub fn disable_ssl_verification(self) -> Self

Disable SSL verification for the HTTP requests.

Source

pub fn user_agent(self, user_agent: impl AsRef<str>) -> Self

Set a custom HTTP user agent for the client.

Source

pub fn add_root_certificates(self, certificates: Vec<Certificate>) -> Self

Add the given list of certificates to the certificate store of the HTTP client.

These additional certificates will be trusted and considered when establishing a HTTP request.

Internally this will call the reqwest::ClientBuilder::add_root_certificate() method.

Source

pub fn disable_built_in_root_certificates(self) -> Self

Don’t trust any system root certificates, only trust the certificates provided through add_root_certificates.

Source

pub fn http_client(self, client: Client) -> Self

Specify a reqwest::Client instance to handle sending requests and receiving responses.

This method is mutually exclusive with proxy(), disable_ssl_verification, add_root_certificates, disable_built_in_root_certificates, and user_agent().

Source

pub fn server_versions( self, value: impl IntoIterator<Item = MatrixVersion>, ) -> Self

Specify the Matrix versions supported by the homeserver manually, rather than build() doing it using a get_supported_versions request.

This is helpful for test code that doesn’t care to mock that endpoint.

Source

pub fn handle_refresh_tokens(self) -> Self

Handle refreshing access tokens automatically.

By default, the Client forwards any error and doesn’t handle errors with the access token, which means that Client::refresh_access_token() needs to be called manually to refresh access tokens.

Enabling this setting means that the Client will try to refresh the token automatically, which means that:

  • If refreshing the token fails, the error is forwarded, so any endpoint can return HttpError::RefreshToken. If an UnknownToken error is encountered, it means that the user needs to be logged in again.

  • The access token and refresh token need to be watched for changes, using the authentication API’s session_tokens_stream() for example, to be able to restore the session later.

Source

pub fn with_encryption_settings(self, settings: EncryptionSettings) -> Self

Enables specific encryption settings that will persist throughout the entire lifetime of the Client.

Source

pub fn with_room_key_recipient_strategy(self, strategy: CollectStrategy) -> Self

Set the strategy to be used for picking recipient devices, when sending an encrypted message.

Source

pub fn with_decryption_trust_requirement( self, trust_requirement: TrustRequirement, ) -> Self

Set the trust requirement to be used when decrypting events.

Source

pub fn cross_process_store_locks_holder_name(self, holder_name: String) -> Self

Set the cross-process store locks holder name.

The SDK provides cross-process store locks (see matrix_sdk_common::store_locks::CrossProcessStoreLock). The holder_name will be the value used for all cross-process store locks used by the Client being built.

If 2 concurrent Clients are running in 2 different process, this method must be called with different hold_name values.

Source

pub async fn build(self) -> Result<Client, ClientBuildError>

Create a Client with the options set on this builder.

§Errors

This method can fail for two general reasons:

  • Invalid input: a missing or invalid homeserver URL or invalid proxy URL
  • HTTP error: If you supplied a user ID instead of a homeserver URL, a server discovery request is made which can fail; if you didn’t set server_versions(false), that amounts to another request that can fail

Trait Implementations§

Source§

impl Clone for ClientBuilder

Source§

fn clone(&self) -> ClientBuilder

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ClientBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

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

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Any for T
where T: Any,

Source§

impl<T> AsyncTraitDeps for T

Source§

impl<T> CloneAny for T
where T: Any + Clone,

Source§

impl<T> CloneAnySend for T
where T: Any + Send + Clone,

Source§

impl<T> CloneAnySendSync for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> CloneAnySync for T
where T: Any + Sync + Clone,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T

Source§

impl<T> SendOutsideWasm for T
where T: Send,

Source§

impl<T> SyncOutsideWasm for T
where T: Sync,