docs(sdk): Remove some unwraps from the encryption doc examples

master
Damir Jelić 2021-09-14 15:05:11 +02:00
parent 7de782d3a2
commit f42883eaad
2 changed files with 32 additions and 29 deletions

View File

@ -65,10 +65,10 @@ impl Device {
/// # use matrix_sdk::{Client, ruma::UserId}; /// # use matrix_sdk::{Client, ruma::UserId};
/// # use url::Url; /// # use url::Url;
/// # use futures::executor::block_on; /// # 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 { /// # 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?; /// let device = client.get_device(&alice, "DEVICEID".into()).await?;
/// ///
/// if let Some(device) = device { /// if let Some(device) = device {
@ -113,10 +113,10 @@ impl Device {
/// # }; /// # };
/// # use url::Url; /// # use url::Url;
/// # use futures::executor::block_on; /// # 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 { /// # 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?; /// let device = client.get_device(&alice, "DEVICEID".into()).await?;
/// ///
/// // We don't want to support showing a QR code, we only support SAS /// // 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 matrix_sdk::{Client, ruma::UserId};
/// # use url::Url; /// # use url::Url;
/// # use futures::executor::block_on; /// # 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 { /// # 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?; /// let device = client.get_device(&alice, "DEVICEID".into()).await?;
/// ///
/// if let Some(device) = device { /// if let Some(device) = device {
@ -211,10 +211,10 @@ impl Device {
/// # }; /// # };
/// # use url::Url; /// # use url::Url;
/// # use futures::executor::block_on; /// # 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 { /// # 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?; /// let device = client.get_device(&alice, "DEVICEID".into()).await?;
/// ///
/// if let Some(device) = device { /// if let Some(device) = device {
@ -253,10 +253,10 @@ impl Device {
/// # }; /// # };
/// # use url::Url; /// # use url::Url;
/// # use futures::executor::block_on; /// # 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 { /// # 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?; /// let user = client.get_user_identity(&alice).await?;
/// ///
/// if let Some(user) = user { /// if let Some(user) = user {

View File

@ -17,7 +17,7 @@ use ruma::UserId;
use crate::{error::Result, Client}; use crate::{error::Result, Client};
/// An object controlling the interactive verification flow. /// An object controlling the short auth string verification flow.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct SasVerification { pub struct SasVerification {
pub(crate) inner: BaseSas, pub(crate) inner: BaseSas,
@ -43,26 +43,29 @@ impl SasVerification {
/// # use futures::executor::block_on; /// # use futures::executor::block_on;
/// # use url::Url; /// # use url::Url;
/// # use ruma::user_id; /// # use ruma::user_id;
/// use matrix_sdk::verification::SasVerification; /// use matrix_sdk::{
/// use matrix_sdk_base::crypto::AcceptSettings; /// encryption::verification::{SasVerification, AcceptSettings},
/// use matrix_sdk::ruma::events::key::verification::ShortAuthenticationString; /// ruma::events::key::verification::ShortAuthenticationString,
/// # let homeserver = Url::parse("http://example.com").unwrap(); /// };
/// # let client = Client::new(homeserver).unwrap(); ///
/// # let flow_id = "someID"; /// # let flow_id = "someID";
/// # let user_id = user_id!("@alice:example"); /// # let user_id = user_id!("@alice:example");
/// # block_on(async { /// # block_on(async {
/// # let homeserver = Url::parse("http://example.com")?;
/// # let client = Client::new(homeserver)?;
/// let sas = client /// let sas = client
/// .get_verification(&user_id, flow_id) /// .get_verification(&user_id, flow_id)
/// .await /// .await
/// .unwrap() /// .and_then(|v| v.sas());
/// .sas()
/// .unwrap();
/// ///
/// let only_decimal = AcceptSettings::with_allowed_methods( /// if let Some(sas) = sas {
/// vec![ShortAuthenticationString::Decimal] /// let only_decimal = AcceptSettings::with_allowed_methods(
/// ); /// vec![ShortAuthenticationString::Decimal]
/// sas.accept_with_settings(only_decimal).await.unwrap(); /// );
/// # }); ///
/// sas.accept_with_settings(only_decimal).await?;
/// }
/// # anyhow::Result::<()>::Ok(()) });
/// ``` /// ```
pub async fn accept_with_settings(&self, settings: AcceptSettings) -> Result<()> { pub async fn accept_with_settings(&self, settings: AcceptSettings) -> Result<()> {
if let Some(request) = self.inner.accept_with_settings(settings) { if let Some(request) = self.inner.accept_with_settings(settings) {