Skip to content

Commit 4636a91

Browse files
committed
chore(sdk): Rename HomeserverConfig variants.
This patch renames `HomeserverConfig::Url` to `HomeserverUrl`, and `HomeserverConfig::ServerNameOrUrl` to `ServerNameOrHomeserverUrl`. Funnily, the methods on `ClientBuilder` doesn't need to be renamed to match the new naming since they already use this naming!
1 parent 5e662e8 commit 4636a91

File tree

2 files changed

+35
-42
lines changed

2 files changed

+35
-42
lines changed

crates/matrix-sdk/src/client/builder/homeserver_config.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ use crate::{
3131
#[derive(Clone, Debug)]
3232
pub(super) enum HomeserverConfig {
3333
/// A homeserver name URL, including the protocol.
34-
Url(String),
34+
HomeserverUrl(String),
3535

3636
/// A server name, with the protocol put apart.
3737
ServerName { server: OwnedServerName, protocol: UrlScheme },
3838

3939
/// A server name with or without the protocol (it will fallback to `https`
4040
/// if absent), or a homeserver URL.
41-
ServerNameOrUrl(String),
41+
ServerNameOrHomeserverUrl(String),
4242
}
4343

4444
/// A simple helper to represent `http` or `https` in a URL.
@@ -62,7 +62,7 @@ impl HomeserverConfig {
6262
http_client: &HttpClient,
6363
) -> Result<HomeserverDiscoveryResult, ClientBuildError> {
6464
Ok(match self {
65-
Self::Url(url) => {
65+
Self::HomeserverUrl(url) => {
6666
let homeserver = Url::parse(url)?;
6767

6868
HomeserverDiscoveryResult {
@@ -85,7 +85,7 @@ impl HomeserverConfig {
8585
}
8686
}
8787

88-
Self::ServerNameOrUrl(server_name_or_url) => {
88+
Self::ServerNameOrHomeserverUrl(server_name_or_url) => {
8989
let (server, homeserver, well_known, supported_versions) =
9090
discover_homeserver_from_server_name_or_url(
9191
server_name_or_url.to_owned(),
@@ -233,7 +233,7 @@ mod tests {
233233
let http_client =
234234
HttpClient::new(HttpSettings::default().make_client().unwrap(), Default::default());
235235

236-
let result = HomeserverConfig::Url("https://matrix-client.matrix.org".to_owned())
236+
let result = HomeserverConfig::HomeserverUrl("https://matrix-client.matrix.org".to_owned())
237237
.discover(&http_client)
238238
.await
239239
.unwrap();
@@ -294,7 +294,7 @@ mod tests {
294294
.mount(&server)
295295
.await;
296296

297-
let result = HomeserverConfig::ServerNameOrUrl(server.uri().to_string())
297+
let result = HomeserverConfig::ServerNameOrHomeserverUrl(server.uri().to_string())
298298
.discover(&http_client)
299299
.await
300300
.unwrap();
@@ -320,7 +320,7 @@ mod tests {
320320
.mount(&homeserver)
321321
.await;
322322

323-
let result = HomeserverConfig::ServerNameOrUrl(homeserver.uri().to_string())
323+
let result = HomeserverConfig::ServerNameOrHomeserverUrl(homeserver.uri().to_string())
324324
.discover(&http_client)
325325
.await
326326
.unwrap();

crates/matrix-sdk/src/client/builder/mod.rs

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -123,24 +123,12 @@ impl ClientBuilder {
123123

124124
/// Set the homeserver URL to use.
125125
///
126-
/// The following methods are mutually exclusive:
127-
/// [`homeserver_url()`][Self::homeserver_url]
128-
/// [`server_name()`][Self::server_name]
129-
/// [`insecure_server_name_no_tls()`][Self::insecure_server_name_no_tls]
130-
/// [`server_name_or_homeserver_url()`][Self::server_name_or_homeserver_url],
126+
/// The following methods are mutually exclusive: [`Self::homeserver_url`],
127+
/// [`Self::server_name`] [`Self::insecure_server_name_no_tls`],
128+
/// [`Self::server_name_or_homeserver_url`].
131129
/// If you set more than one, then whatever was set last will be used.
132130
pub fn homeserver_url(mut self, url: impl AsRef<str>) -> Self {
133-
self.homeserver_cfg = Some(HomeserverConfig::Url(url.as_ref().to_owned()));
134-
self
135-
}
136-
137-
/// Set sliding sync to a specific version.
138-
#[cfg(feature = "experimental-sliding-sync")]
139-
pub fn sliding_sync_version_builder(
140-
mut self,
141-
version_builder: SlidingSyncVersionBuilder,
142-
) -> Self {
143-
self.sliding_sync_version_builder = version_builder;
131+
self.homeserver_cfg = Some(HomeserverConfig::HomeserverUrl(url.as_ref().to_owned()));
144132
self
145133
}
146134

@@ -149,11 +137,9 @@ impl ClientBuilder {
149137
/// We assume we can connect in HTTPS to that server. If that's not the
150138
/// case, prefer using [`Self::insecure_server_name_no_tls`].
151139
///
152-
/// The following methods are mutually exclusive:
153-
/// [`homeserver_url()`][Self::homeserver_url]
154-
/// [`server_name()`][Self::server_name]
155-
/// [`insecure_server_name_no_tls()`][Self::insecure_server_name_no_tls]
156-
/// [`server_name_or_homeserver_url()`][Self::server_name_or_homeserver_url],
140+
/// The following methods are mutually exclusive: [`Self::homeserver_url`],
141+
/// [`Self::server_name`] [`Self::insecure_server_name_no_tls`],
142+
/// [`Self::server_name_or_homeserver_url`].
157143
/// If you set more than one, then whatever was set last will be used.
158144
pub fn server_name(mut self, server_name: &ServerName) -> Self {
159145
self.homeserver_cfg = Some(HomeserverConfig::ServerName {
@@ -168,11 +154,9 @@ impl ClientBuilder {
168154
/// (not secured) scheme. This also relaxes OIDC discovery checks to allow
169155
/// HTTP schemes.
170156
///
171-
/// The following methods are mutually exclusive:
172-
/// [`homeserver_url()`][Self::homeserver_url]
173-
/// [`server_name()`][Self::server_name]
174-
/// [`insecure_server_name_no_tls()`][Self::insecure_server_name_no_tls]
175-
/// [`server_name_or_homeserver_url()`][Self::server_name_or_homeserver_url],
157+
/// The following methods are mutually exclusive: [`Self::homeserver_url`],
158+
/// [`Self::server_name`] [`Self::insecure_server_name_no_tls`],
159+
/// [`Self::server_name_or_homeserver_url`].
176160
/// If you set more than one, then whatever was set last will be used.
177161
pub fn insecure_server_name_no_tls(mut self, server_name: &ServerName) -> Self {
178162
self.homeserver_cfg = Some(HomeserverConfig::ServerName {
@@ -185,18 +169,27 @@ impl ClientBuilder {
185169
/// Set the server name to discover the homeserver from, falling back to
186170
/// using it as a homeserver URL if discovery fails. When falling back to a
187171
/// homeserver URL, a check is made to ensure that the server exists (unlike
188-
/// [`homeserver_url()`][Self::homeserver_url]), so you can guarantee that
189-
/// the client is ready to use.
172+
/// [`Self::homeserver_url`], so you can guarantee that the client is ready
173+
/// to use.
190174
///
191-
/// The following methods are mutually exclusive:
192-
/// [`homeserver_url()`][Self::homeserver_url]
193-
/// [`server_name()`][Self::server_name]
194-
/// [`insecure_server_name_no_tls()`][Self::insecure_server_name_no_tls]
195-
/// [`server_name_or_homeserver_url()`][Self::server_name_or_homeserver_url],
175+
/// The following methods are mutually exclusive: [`Self::homeserver_url`],
176+
/// [`Self::server_name`] [`Self::insecure_server_name_no_tls`],
177+
/// [`Self::server_name_or_homeserver_url`].
196178
/// If you set more than one, then whatever was set last will be used.
197179
pub fn server_name_or_homeserver_url(mut self, server_name_or_url: impl AsRef<str>) -> Self {
198-
self.homeserver_cfg =
199-
Some(HomeserverConfig::ServerNameOrUrl(server_name_or_url.as_ref().to_owned()));
180+
self.homeserver_cfg = Some(HomeserverConfig::ServerNameOrHomeserverUrl(
181+
server_name_or_url.as_ref().to_owned(),
182+
));
183+
self
184+
}
185+
186+
/// Set sliding sync to a specific version.
187+
#[cfg(feature = "experimental-sliding-sync")]
188+
pub fn sliding_sync_version_builder(
189+
mut self,
190+
version_builder: SlidingSyncVersionBuilder,
191+
) -> Self {
192+
self.sliding_sync_version_builder = version_builder;
200193
self
201194
}
202195

0 commit comments

Comments
 (0)