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.

Example

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 matrix_sdk::Client;
use std::sync::Arc;

// 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(Arc::new(reqwest_builder.build()?));

Implementations

Set the homeserver URL to use.

This method is mutually exclusive with user_id(), if you set both whatever was set last will be used.

Set the user ID to discover the homeserver from.

builder.user_id(id) is a shortcut for builder.server_name(id.server_name()).

This method is mutually exclusive with homeserver_url(), if you set both whatever was set last will be used.

Set the server name to discover the homeserver from.

This method is mutually exclusive with homeserver_url(), if you set both whatever was set last will be used.

Create a new ClientConfig with the given StoreConfig.

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

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

let store_config = StoreConfig::new().state_store(custom_state_store);
let client_builder = Client::builder().store_config(store_config);

Set a custom implementation of a StateStore.

The state store should be opened before being set.

Available on crate feature e2e-encryption only.

Set a custom implementation of a CryptoStore.

The crypto store should be opened before being set.

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

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

Available on non-WebAssembly only.

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.
Example
use matrix_sdk::Client;

let client_config = Client::builder()
    .proxy("http://localhost:8080");
Available on non-WebAssembly only.

Disable SSL verification for the HTTP requests.

Available on non-WebAssembly only.

Set a custom HTTP user agent for the client.

Specify an HTTP client to handle sending requests and receiving responses.

Any type that implements the HttpSend trait can be used to send / receive http types.

This method is mutually exclusive with user_agent(),

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.

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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

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