Skip to content

Commit 2456bea

Browse files
committed
Make Result alias more flexible
1 parent cc6f97b commit 2456bea

File tree

8 files changed

+31
-34
lines changed

8 files changed

+31
-34
lines changed

crates/matrix-sdk-appservice/src/webserver/warp.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use std::{net::ToSocketAddrs, result::Result as StdResult};
15+
use std::net::ToSocketAddrs;
1616

1717
use matrix_sdk::{
1818
bytes::Bytes,
@@ -168,7 +168,7 @@ mod handlers {
168168
_user_id: String,
169169
appservice: AppService,
170170
request: http::Request<Bytes>,
171-
) -> StdResult<impl warp::Reply, Rejection> {
171+
) -> Result<impl warp::Reply, Rejection> {
172172
if let Some(user_exists) = appservice.event_handler.users.lock().await.as_mut() {
173173
let request =
174174
query_user::IncomingRequest::try_from_http_request(request).map_err(Error::from)?;
@@ -185,7 +185,7 @@ mod handlers {
185185
_room_id: String,
186186
appservice: AppService,
187187
request: http::Request<Bytes>,
188-
) -> StdResult<impl warp::Reply, Rejection> {
188+
) -> Result<impl warp::Reply, Rejection> {
189189
if let Some(room_exists) = appservice.event_handler.rooms.lock().await.as_mut() {
190190
let request =
191191
query_room::IncomingRequest::try_from_http_request(request).map_err(Error::from)?;
@@ -202,7 +202,7 @@ mod handlers {
202202
_txn_id: String,
203203
appservice: AppService,
204204
request: http::Request<Bytes>,
205-
) -> StdResult<impl warp::Reply, Rejection> {
205+
) -> Result<impl warp::Reply, Rejection> {
206206
let incoming_transaction: ruma::api::appservice::event::push_events::v1::IncomingRequest =
207207
ruma::api::IncomingRequest::try_from_http_request(request).map_err(Error::from)?;
208208

@@ -224,7 +224,7 @@ struct ErrorMessage {
224224
message: String,
225225
}
226226

227-
pub async fn handle_rejection(err: Rejection) -> std::result::Result<impl Reply, Rejection> {
227+
pub async fn handle_rejection(err: Rejection) -> Result<impl Reply, Rejection> {
228228
if err.find::<Unauthorized>().is_some() || err.find::<warp::reject::InvalidQuery>().is_some() {
229229
let code = http::StatusCode::UNAUTHORIZED;
230230
let message = "UNAUTHORIZED";

crates/matrix-sdk/src/client.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl Client {
230230
///
231231
/// // Finally let's try to login.
232232
/// client.login(alice, "password", None, None).await?;
233-
/// # matrix_sdk::Result::Ok(()) });
233+
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
234234
/// ```
235235
///
236236
/// [spec]: https://spec.matrix.org/unstable/client-server-api/#well-known-uri
@@ -866,7 +866,7 @@ impl Client {
866866
/// "Logged in as {}, got device_id {} and access_token {}",
867867
/// user, response.device_id, response.access_token
868868
/// );
869-
/// # matrix_sdk::Result::Ok(()) });
869+
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
870870
/// ```
871871
///
872872
/// [`restore_login`]: #method.restore_login
@@ -1528,7 +1528,7 @@ impl Client {
15281528
/// for room in response.chunk {
15291529
/// println!("Found room {:?}", room);
15301530
/// }
1531-
/// # matrix_sdk::Result::Ok(()) });
1531+
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
15321532
/// ```
15331533
pub async fn public_rooms_filtered(
15341534
&self,
@@ -1628,7 +1628,7 @@ impl Client {
16281628
///
16291629
/// // Check the corresponding Response struct to find out what types are
16301630
/// // returned
1631-
/// # matrix_sdk::Result::Ok(()) });
1631+
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
16321632
/// ```
16331633
pub async fn send<Request>(
16341634
&self,
@@ -1663,7 +1663,7 @@ impl Client {
16631663
/// device.display_name.as_deref().unwrap_or("")
16641664
/// );
16651665
/// }
1666-
/// # matrix_sdk::Result::Ok(()) });
1666+
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
16671667
/// ```
16681668
pub async fn devices(&self) -> HttpResult<get_devices::Response> {
16691669
let request = get_devices::Request::new();
@@ -1716,7 +1716,7 @@ impl Client {
17161716
/// .await?;
17171717
/// }
17181718
/// }
1719-
/// # matrix_sdk::Result::Ok(()) });
1719+
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
17201720
pub async fn delete_devices(
17211721
&self,
17221722
devices: &[DeviceIdBox],
@@ -1805,7 +1805,7 @@ impl Client {
18051805
/// // Now keep on syncing forever. `sync()` will use the stored sync token
18061806
/// // from our `sync_once()` call automatically.
18071807
/// client.sync(SyncSettings::default()).await;
1808-
/// # matrix_sdk::Result::Ok(()) });
1808+
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
18091809
/// ```
18101810
///
18111811
/// [`sync`]: #method.sync
@@ -1896,7 +1896,7 @@ impl Client {
18961896
/// // Now keep on syncing forever. `sync()` will use the latest sync token
18971897
/// // automatically.
18981898
/// client.sync(SyncSettings::default()).await;
1899-
/// # matrix_sdk::Result::Ok(()) });
1899+
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
19001900
/// ```
19011901
///
19021902
/// [argument docs]: #method.sync_once
@@ -2025,7 +2025,7 @@ impl Client {
20252025
/// }
20262026
/// }
20272027
///
2028-
/// # matrix_sdk::Result::Ok(()) });
2028+
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
20292029
/// ```
20302030
#[instrument]
20312031
pub async fn sync_stream<'a>(

crates/matrix-sdk/src/config/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl ClientConfig {
8989
/// let client_config = ClientConfig::new()
9090
/// .proxy("http://localhost:8080")?;
9191
///
92-
/// # matrix_sdk::Result::Ok(())
92+
/// # Result::<_, matrix_sdk::Error>::Ok(())
9393
/// ```
9494
#[cfg(not(target_arch = "wasm32"))]
9595
pub fn proxy(mut self, proxy: &str) -> Result<Self> {
@@ -104,7 +104,7 @@ impl ClientConfig {
104104
}
105105

106106
/// Set a custom HTTP user agent for the client.
107-
pub fn user_agent(mut self, user_agent: &str) -> std::result::Result<Self, InvalidHeaderValue> {
107+
pub fn user_agent(mut self, user_agent: &str) -> Result<Self, InvalidHeaderValue> {
108108
self.user_agent = Some(HeaderValue::from_str(user_agent)?);
109109
Ok(self)
110110
}

crates/matrix-sdk/src/encryption/identities/devices.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use std::{ops::Deref, result::Result as StdResult};
15+
use std::ops::Deref;
1616

1717
use matrix_sdk_base::crypto::{
1818
store::CryptoStoreError, Device as BaseDevice, LocalTrust, ReadOnlyDevice,
@@ -250,7 +250,7 @@ impl Device {
250250
/// }
251251
/// # anyhow::Result::<()>::Ok(()) });
252252
/// ```
253-
pub async fn verify(&self) -> std::result::Result<(), ManualVerifyError> {
253+
pub async fn verify(&self) -> Result<(), ManualVerifyError> {
254254
let request = self.inner.verify().await?;
255255
self.client.send(request, None).await?;
256256

@@ -391,10 +391,7 @@ impl Device {
391391
/// # Arguments
392392
///
393393
/// * `trust_state` - The new trust state that should be set for the device.
394-
pub async fn set_local_trust(
395-
&self,
396-
trust_state: LocalTrust,
397-
) -> StdResult<(), CryptoStoreError> {
394+
pub async fn set_local_trust(&self, trust_state: LocalTrust) -> Result<(), CryptoStoreError> {
398395
self.inner.set_local_trust(trust_state).await
399396
}
400397
}

crates/matrix-sdk/src/encryption/identities/users.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use std::{result::Result, sync::Arc};
15+
use std::sync::Arc;
1616

1717
use matrix_sdk_base::{
1818
crypto::{

crates/matrix-sdk/src/encryption/verification/qrcode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl QrVerification {
7171
///
7272
/// The [`to_bytes()`](#method.to_bytes) method can be used to instead
7373
/// output the raw bytes that should be encoded as a QR code.
74-
pub fn to_qr_code(&self) -> std::result::Result<QrCode, EncodingError> {
74+
pub fn to_qr_code(&self) -> Result<QrCode, EncodingError> {
7575
self.inner.to_qr_code()
7676
}
7777

@@ -80,7 +80,7 @@ impl QrVerification {
8080
///
8181
/// The [`to_qr_code()`](#method.to_qr_code) method can be used to instead
8282
/// output a `QrCode` object that can be rendered.
83-
pub fn to_bytes(&self) -> std::result::Result<Vec<u8>, EncodingError> {
83+
pub fn to_bytes(&self) -> Result<Vec<u8>, EncodingError> {
8484
self.inner.to_bytes()
8585
}
8686

crates/matrix-sdk/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use thiserror::Error;
4040
use url::ParseError as UrlParseError;
4141

4242
/// Result type of the matrix-sdk.
43-
pub type Result<T> = std::result::Result<T, Error>;
43+
pub type Result<T, E = Error> = std::result::Result<T, E>;
4444

4545
/// Result type of a pure HTTP request.
4646
pub type HttpResult<T> = std::result::Result<T, HttpError>;

crates/matrix-sdk/src/room/joined.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl Joined {
170170
/// if let Some(room) = client.get_joined_room(&room_id) {
171171
/// room.typing_notice(true).await?
172172
/// }
173-
/// # matrix_sdk::Result::Ok(()) });
173+
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
174174
/// ```
175175
pub async fn typing_notice(&self, typing: bool) -> Result<()> {
176176
// Only send a request to the homeserver if the old timeout has elapsed
@@ -278,7 +278,7 @@ impl Joined {
278278
/// if let Some(room) = client.get_joined_room(&room_id) {
279279
/// room.enable_encryption().await?
280280
/// }
281-
/// # matrix_sdk::Result::Ok(()) });
281+
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
282282
/// ```
283283
pub async fn enable_encryption(&self) -> Result<()> {
284284
use ruma::{
@@ -449,7 +449,7 @@ impl Joined {
449449
/// if let Some(room) = client.get_joined_room(&room_id) {
450450
/// room.send(content, Some(txn_id)).await?;
451451
/// }
452-
/// # matrix_sdk::Result::Ok(()) });
452+
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
453453
/// ```
454454
///
455455
/// [`SyncMessageEvent`]: ruma::events::SyncMessageEvent
@@ -517,7 +517,7 @@ impl Joined {
517517
/// if let Some(room) = client.get_joined_room(&room_id) {
518518
/// room.send_raw(content, "m.room.message", None).await?;
519519
/// }
520-
/// # matrix_sdk::Result::Ok(()) });
520+
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
521521
/// ```
522522
///
523523
/// [`SyncMessageEvent`]: ruma::events::SyncMessageEvent
@@ -631,7 +631,7 @@ impl Joined {
631631
/// None,
632632
/// ).await?;
633633
/// }
634-
/// # matrix_sdk::Result::Ok(()) });
634+
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
635635
/// ```
636636
pub async fn send_attachment<R: Read>(
637637
&self,
@@ -698,7 +698,7 @@ impl Joined {
698698
/// if let Some(room) = client.get_joined_room(&room_id) {
699699
/// room.send_state_event(content, "").await?;
700700
/// }
701-
/// # matrix_sdk::Result::Ok(()) });
701+
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
702702
/// ```
703703
pub async fn send_state_event(
704704
&self,
@@ -791,7 +791,7 @@ impl Joined {
791791
/// let reason = Some("Indecent material");
792792
/// room.redact(&event_id, reason, None).await?;
793793
/// }
794-
/// # matrix_sdk::Result::Ok(()) });
794+
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
795795
/// ```
796796
pub async fn redact(
797797
&self,
@@ -834,7 +834,7 @@ impl Joined {
834834
///
835835
/// room.set_tag("u.work", tag_info ).await?;
836836
/// }
837-
/// # matrix_sdk::Result::Ok(()) });
837+
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
838838
/// ```
839839
pub async fn set_tag(&self, tag: &str, tag_info: TagInfo) -> HttpResult<create_tag::Response> {
840840
let user_id = self.client.user_id().await.ok_or(HttpError::AuthenticationRequired)?;

0 commit comments

Comments
 (0)