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 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(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.

👎Deprecated: Use server_name(user_id.server_name()) instead

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.

Available on crate feature sled only.

Set up the store configuration for a sled store.

This is a shorthand for .store_config(matrix_sdk_sled::make_store_config(path, passphrase)?).

Set up the store configuration.

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::{config::StoreConfig, Client};

let store_config = StoreConfig::new().state_store(custom_state_store);
let client_builder = Client::builder().store_config(store_config);
👎Deprecated: Use store_config, sled_store or indexeddb_store instead

Set a custom implementation of a StateStore.

The state store should be opened before being set.

👎Deprecated: Use store_config, sled_store or indexeddb_store instead
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.

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:

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

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
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 resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
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