Struct matrix_sdk::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.
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
sourceimpl ClientBuilder
impl ClientBuilder
sourcepub fn homeserver_url(self, url: impl AsRef<str>) -> Self
pub fn homeserver_url(self, url: impl AsRef<str>) -> Self
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.
sourcepub fn user_id(self, user_id: &UserId) -> Self
pub fn user_id(self, user_id: &UserId) -> Self
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.
sourcepub fn server_name(self, server_name: &ServerName) -> Self
pub fn server_name(self, server_name: &ServerName) -> Self
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.
sourcepub fn store_config(self, store_config: StoreConfig) -> Self
pub fn store_config(self, store_config: StoreConfig) -> Self
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);
sourcepub fn state_store(self, store: Box<dyn StateStore>) -> Self
pub fn state_store(self, store: Box<dyn StateStore>) -> Self
Set a custom implementation of a StateStore
.
The state store should be opened before being set.
sourcepub fn crypto_store(self, store: Box<dyn CryptoStore>) -> Self
Available on crate feature e2e-encryption
only.
pub fn crypto_store(self, store: Box<dyn CryptoStore>) -> Self
e2e-encryption
only.Set a custom implementation of a CryptoStore
.
The crypto store should be opened before being set.
sourcepub fn respect_login_well_known(self, value: bool) -> Self
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.
sourcepub fn request_config(self, request_config: RequestConfig) -> Self
pub fn request_config(self, request_config: RequestConfig) -> Self
Set the default timeout, fail and retry behavior for all HTTP requests.
sourcepub fn disable_ssl_verification(self) -> Self
Available on non-WebAssembly only.
pub fn disable_ssl_verification(self) -> Self
Disable SSL verification for the HTTP requests.
sourcepub fn user_agent(self, user_agent: impl AsRef<str>) -> Self
Available on non-WebAssembly only.
pub fn user_agent(self, user_agent: impl AsRef<str>) -> Self
Set a custom HTTP user agent for the client.
sourcepub fn http_client(self, client: Arc<dyn HttpSend>) -> Self
pub fn http_client(self, client: Arc<dyn HttpSend>) -> Self
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()
,
sourcepub fn server_versions(
self,
value: impl IntoIterator<Item = MatrixVersion>
) -> Self
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.
sourcepub async fn build(self) -> Result<Client, ClientBuildError>
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
Auto Trait Implementations
impl !RefUnwindSafe for ClientBuilder
impl Send for ClientBuilder
impl Sync for ClientBuilder
impl Unpin for ClientBuilder
impl !UnwindSafe for ClientBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more