From 05a190ee5ab1cbee4d827415f6cd31dcdb40db0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 8 Nov 2021 17:17:42 +0100 Subject: [PATCH] docs(sdk): Add an example that prints out the SAS emojis --- .../src/encryption/verification/sas.rs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/crates/matrix-sdk/src/encryption/verification/sas.rs b/crates/matrix-sdk/src/encryption/verification/sas.rs index ef6df22f2..ef4791f1e 100644 --- a/crates/matrix-sdk/src/encryption/verification/sas.rs +++ b/crates/matrix-sdk/src/encryption/verification/sas.rs @@ -99,6 +99,46 @@ impl SasVerification { } /// Get the emoji version of the short auth string. + /// + /// # Examples + /// + /// ```no_run + /// # use matrix_sdk::Client; + /// # use futures::executor::block_on; + /// # use url::Url; + /// # use ruma::user_id; + /// 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_verification = client + /// .get_verification(&user_id, flow_id) + /// .await + /// .and_then(|v| v.sas()); + /// + /// if let Some(emojis) = sas_verification.and_then(|s| s.emoji()) { + /// let emoji_string = emojis + /// .iter() + /// .map(|e| format!("{:^12}", e.symbol)) + /// .collect::>() + /// .join(""); + /// + /// let description = emojis + /// .iter() + /// .map(|e| format!("{:^12}", e.description)) + /// .collect::>() + /// .join(""); + /// + /// println!("Do the emojis match?\n{}\n{}", emoji_string, description); + /// } + /// # anyhow::Result::<()>::Ok(()) }); + /// ``` pub fn emoji(&self) -> Option<[super::Emoji; 7]> { self.inner.emoji() }