From 9ff70228d8eb83342cbb61e44d1946fe4142fa70 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Fri, 1 Nov 2024 13:30:22 +0000 Subject: [PATCH] identifiers: Add doc tests for algorithm and key_name --- crates/ruma-common/src/identifiers/key_id.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/ruma-common/src/identifiers/key_id.rs b/crates/ruma-common/src/identifiers/key_id.rs index 5efff4a9..8d2e5b81 100644 --- a/crates/ruma-common/src/identifiers/key_id.rs +++ b/crates/ruma-common/src/identifiers/key_id.rs @@ -63,12 +63,28 @@ impl KeyId { Self::from_borrowed(&res).to_owned() } - /// Returns key algorithm of the key ID. + /// Returns key algorithm of the key ID - the part that comes before the colon. + /// + /// # Example + /// + /// ```rust + /// use ruma_common::{DeviceId, DeviceKeyAlgorithm, KeyId, OwnedKeyId}; + /// let k: OwnedKeyId = KeyId::parse("ed25519:1").unwrap(); + /// assert_eq!(k.algorithm().as_str(), "ed25519"); + /// ``` pub fn algorithm(&self) -> A { A::from(&self.as_str()[..self.colon_idx()]) } - /// Returns the key name of the key ID. + /// Returns the key name of the key ID - the part that comes after the colon. + /// + /// # Example + /// + /// ```rust + /// use ruma_common::{DeviceId, DeviceKeyAlgorithm, KeyId, OwnedKeyId}; + /// let k: OwnedKeyId = KeyId::parse("ed25519:foo").unwrap(); + /// assert_eq!(k.key_name(), "foo"); + /// ``` pub fn key_name<'a>(&'a self) -> &'a K where &'a K: TryFrom<&'a str>,