From f42883eaaddeed6410d356159e468fc1282134af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 14 Sep 2021 15:05:11 +0200 Subject: [PATCH] docs(sdk): Remove some unwraps from the encryption doc examples --- .../src/encryption/identities/devices.rs | 30 +++++++++--------- .../src/encryption/verification/sas.rs | 31 ++++++++++--------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/crates/matrix_sdk/src/encryption/identities/devices.rs b/crates/matrix_sdk/src/encryption/identities/devices.rs index eb615620..cb1f0d47 100644 --- a/crates/matrix_sdk/src/encryption/identities/devices.rs +++ b/crates/matrix_sdk/src/encryption/identities/devices.rs @@ -65,10 +65,10 @@ impl Device { /// # use matrix_sdk::{Client, ruma::UserId}; /// # use url::Url; /// # use futures::executor::block_on; - /// # let alice = UserId::try_from("@alice:example.org").unwrap(); - /// # let homeserver = Url::parse("http://example.com").unwrap(); - /// # let client = Client::new(homeserver).unwrap(); /// # block_on(async { + /// # let alice = UserId::try_from("@alice:example.org")?; + /// # let homeserver = Url::parse("http://example.com")?; + /// # let client = Client::new(homeserver)?; /// let device = client.get_device(&alice, "DEVICEID".into()).await?; /// /// if let Some(device) = device { @@ -113,10 +113,10 @@ impl Device { /// # }; /// # use url::Url; /// # use futures::executor::block_on; - /// # let alice = UserId::try_from("@alice:example.org").unwrap(); - /// # let homeserver = Url::parse("http://example.com").unwrap(); - /// # let client = Client::new(homeserver).unwrap(); /// # block_on(async { + /// # let alice = UserId::try_from("@alice:example.org")?; + /// # let homeserver = Url::parse("http://example.com")?; + /// # let client = Client::new(homeserver)?; /// let device = client.get_device(&alice, "DEVICEID".into()).await?; /// /// // We don't want to support showing a QR code, we only support SAS @@ -157,10 +157,10 @@ impl Device { /// # use matrix_sdk::{Client, ruma::UserId}; /// # use url::Url; /// # use futures::executor::block_on; - /// # let alice = UserId::try_from("@alice:example.org").unwrap(); - /// # let homeserver = Url::parse("http://example.com").unwrap(); - /// # let client = Client::new(homeserver).unwrap(); /// # block_on(async { + /// # let alice = UserId::try_from("@alice:example.org")?; + /// # let homeserver = Url::parse("http://example.com")?; + /// # let client = Client::new(homeserver)?; /// let device = client.get_device(&alice, "DEVICEID".into()).await?; /// /// if let Some(device) = device { @@ -211,10 +211,10 @@ impl Device { /// # }; /// # use url::Url; /// # use futures::executor::block_on; - /// # let alice = UserId::try_from("@alice:example.org").unwrap(); - /// # let homeserver = Url::parse("http://example.com").unwrap(); - /// # let client = Client::new(homeserver).unwrap(); /// # block_on(async { + /// # let alice = UserId::try_from("@alice:example.org")?; + /// # let homeserver = Url::parse("http://example.com")?; + /// # let client = Client::new(homeserver)?; /// let device = client.get_device(&alice, "DEVICEID".into()).await?; /// /// if let Some(device) = device { @@ -253,10 +253,10 @@ impl Device { /// # }; /// # use url::Url; /// # use futures::executor::block_on; - /// # let alice = UserId::try_from("@alice:example.org").unwrap(); - /// # let homeserver = Url::parse("http://example.com").unwrap(); - /// # let client = Client::new(homeserver).unwrap(); /// # block_on(async { + /// # let alice = UserId::try_from("@alice:example.org")?; + /// # let homeserver = Url::parse("http://example.com")?; + /// # let client = Client::new(homeserver)?; /// let user = client.get_user_identity(&alice).await?; /// /// if let Some(user) = user { diff --git a/crates/matrix_sdk/src/encryption/verification/sas.rs b/crates/matrix_sdk/src/encryption/verification/sas.rs index 3cb46641..dc28f76c 100644 --- a/crates/matrix_sdk/src/encryption/verification/sas.rs +++ b/crates/matrix_sdk/src/encryption/verification/sas.rs @@ -17,7 +17,7 @@ use ruma::UserId; use crate::{error::Result, Client}; -/// An object controlling the interactive verification flow. +/// An object controlling the short auth string verification flow. #[derive(Debug, Clone)] pub struct SasVerification { pub(crate) inner: BaseSas, @@ -43,26 +43,29 @@ impl SasVerification { /// # use futures::executor::block_on; /// # use url::Url; /// # use ruma::user_id; - /// use matrix_sdk::verification::SasVerification; - /// use matrix_sdk_base::crypto::AcceptSettings; - /// use matrix_sdk::ruma::events::key::verification::ShortAuthenticationString; - /// # let homeserver = Url::parse("http://example.com").unwrap(); - /// # let client = Client::new(homeserver).unwrap(); + /// use matrix_sdk::{ + /// encryption::verification::{SasVerification, AcceptSettings}, + /// ruma::events::key::verification::ShortAuthenticationString, + /// }; + /// /// # let flow_id = "someID"; /// # let user_id = user_id!("@alice:example"); /// # block_on(async { + /// # let homeserver = Url::parse("http://example.com")?; + /// # let client = Client::new(homeserver)?; /// let sas = client /// .get_verification(&user_id, flow_id) /// .await - /// .unwrap() - /// .sas() - /// .unwrap(); + /// .and_then(|v| v.sas()); /// - /// let only_decimal = AcceptSettings::with_allowed_methods( - /// vec![ShortAuthenticationString::Decimal] - /// ); - /// sas.accept_with_settings(only_decimal).await.unwrap(); - /// # }); + /// if let Some(sas) = sas { + /// let only_decimal = AcceptSettings::with_allowed_methods( + /// vec![ShortAuthenticationString::Decimal] + /// ); + /// + /// sas.accept_with_settings(only_decimal).await?; + /// } + /// # anyhow::Result::<()>::Ok(()) }); /// ``` pub async fn accept_with_settings(&self, settings: AcceptSettings) -> Result<()> { if let Some(request) = self.inner.accept_with_settings(settings) {