Format code in doc comments

This commit is contained in:
Jonas Platte 2022-02-18 11:33:16 +01:00
parent 215cb35806
commit 41d6bcc2a6
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
12 changed files with 38 additions and 45 deletions

View File

@ -1,4 +1,5 @@
comment_width = 100 comment_width = 100
format_code_in_doc_comments = true
imports_granularity = "Crate" imports_granularity = "Crate"
newline_style = "Unix" newline_style = "Unix"
use_small_heuristics = "Max" use_small_heuristics = "Max"

View File

@ -56,13 +56,16 @@
//! # let client = MatrixClient::new(homeserver_url, None); //! # let client = MatrixClient::new(homeserver_url, None);
//! use std::convert::TryFrom; //! use std::convert::TryFrom;
//! //!
//! use ruma_api::MatrixVersion;
//! use ruma_client_api::alias::get_alias; //! use ruma_client_api::alias::get_alias;
//! use ruma_identifiers::{room_alias_id, room_id}; //! use ruma_identifiers::{room_alias_id, room_id};
//! use ruma_api::MatrixVersion;
//! //!
//! async { //! async {
//! let response = client //! let response = client
//! .send_request(get_alias::v3::Request::new(room_alias_id!("#example_room:example.com")), &[MatrixVersion::V1_0]) //! .send_request(
//! get_alias::v3::Request::new(room_alias_id!("#example_room:example.com")),
//! &[MatrixVersion::V1_0],
//! )
//! .await?; //! .await?;
//! //!
//! assert_eq!(response.room_id, room_id!("!n8f893n9:example.com")); //! assert_eq!(response.room_id, room_id!("!n8f893n9:example.com"));

View File

@ -9,7 +9,7 @@ use crate::generate_localpart;
/// # Example /// # Example
/// ///
/// ``` /// ```
/// use ruma_identifiers::{DeviceId, device_id}; /// use ruma_identifiers::{device_id, DeviceId};
/// ///
/// let random_id = DeviceId::new(); /// let random_id = DeviceId::new();
/// assert_eq!(random_id.as_str().len(), 8); /// assert_eq!(random_id.as_str().len(), 8);

View File

@ -20,10 +20,7 @@ use crate::ServerName;
/// # use std::convert::TryFrom; /// # use std::convert::TryFrom;
/// # use ruma_identifiers::EventId; /// # use ruma_identifiers::EventId;
/// // Original format /// // Original format
/// assert_eq!( /// assert_eq!(<&EventId>::try_from("$h29iv0s8:example.com").unwrap(), "$h29iv0s8:example.com");
/// <&EventId>::try_from("$h29iv0s8:example.com").unwrap(),
/// "$h29iv0s8:example.com"
/// );
/// // Room version 3 format /// // Room version 3 format
/// assert_eq!( /// assert_eq!(
/// <&EventId>::try_from("$acR1l0raoZnm60CBwAVgqbZqoO/mYU81xysh1u7XcJk").unwrap(), /// <&EventId>::try_from("$acR1l0raoZnm60CBwAVgqbZqoO/mYU81xysh1u7XcJk").unwrap(),

View File

@ -10,10 +10,7 @@ use crate::{server_name::ServerName, EventId, MatrixToRef};
/// ``` /// ```
/// # use std::convert::TryFrom; /// # use std::convert::TryFrom;
/// # use ruma_identifiers::RoomAliasId; /// # use ruma_identifiers::RoomAliasId;
/// assert_eq!( /// assert_eq!(<&RoomAliasId>::try_from("#ruma:example.com").unwrap(), "#ruma:example.com");
/// <&RoomAliasId>::try_from("#ruma:example.com").unwrap(),
/// "#ruma:example.com"
/// );
/// ``` /// ```
#[repr(transparent)] #[repr(transparent)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(PartialEq, Eq, PartialOrd, Ord, Hash)]

View File

@ -10,10 +10,7 @@ use crate::{EventId, MatrixToRef, ServerName};
/// ``` /// ```
/// # use std::convert::TryFrom; /// # use std::convert::TryFrom;
/// # use ruma_identifiers::RoomId; /// # use ruma_identifiers::RoomId;
/// assert_eq!( /// assert_eq!(<&RoomId>::try_from("!n8f893n9:example.com").unwrap(), "!n8f893n9:example.com");
/// <&RoomId>::try_from("!n8f893n9:example.com").unwrap(),
/// "!n8f893n9:example.com"
/// );
/// ``` /// ```
#[repr(transparent)] #[repr(transparent)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(PartialEq, Eq, PartialOrd, Ord, Hash)]

View File

@ -13,10 +13,7 @@ use crate::{server_name::ServerName, RoomAliasId, RoomId};
/// ``` /// ```
/// # use std::convert::TryFrom; /// # use std::convert::TryFrom;
/// # use ruma_identifiers::RoomOrAliasId; /// # use ruma_identifiers::RoomOrAliasId;
/// assert_eq!( /// assert_eq!(<&RoomOrAliasId>::try_from("#ruma:example.com").unwrap(), "#ruma:example.com");
/// <&RoomOrAliasId>::try_from("#ruma:example.com").unwrap(),
/// "#ruma:example.com"
/// );
/// ///
/// assert_eq!( /// assert_eq!(
/// <&RoomOrAliasId>::try_from("!n8f893n9:example.com").unwrap(), /// <&RoomOrAliasId>::try_from("!n8f893n9:example.com").unwrap(),

View File

@ -12,7 +12,8 @@ pub type EntitySignatures<K> = BTreeMap<Box<SigningKeyId<K>>, String>;
/// let key_identifier = KeyId::from_parts(SigningKeyAlgorithm::Ed25519, "1"); /// let key_identifier = KeyId::from_parts(SigningKeyAlgorithm::Ed25519, "1");
/// let mut signatures = Signatures::new(); /// let mut signatures = Signatures::new();
/// let server_name = server_name!("example.org"); /// let server_name = server_name!("example.org");
/// let signature = "YbJva03ihSj5mPk+CHMJKUKlCXCPFXjXOK6VqBnN9nA2evksQcTGn6hwQfrgRHIDDXO2le49x7jnWJHMJrJoBQ"; /// let signature =
/// "YbJva03ihSj5mPk+CHMJKUKlCXCPFXjXOK6VqBnN9nA2evksQcTGn6hwQfrgRHIDDXO2le49x7jnWJHMJrJoBQ";
/// signatures.insert(server_name, key_identifier, signature.into()); /// signatures.insert(server_name, key_identifier, signature.into());
/// ``` /// ```
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]

View File

@ -12,10 +12,7 @@ use crate::{MatrixToRef, ServerName};
/// ``` /// ```
/// # use std::convert::TryFrom; /// # use std::convert::TryFrom;
/// # use ruma_identifiers::UserId; /// # use ruma_identifiers::UserId;
/// assert_eq!( /// assert_eq!(<&UserId>::try_from("@carl:example.com").unwrap(), "@carl:example.com");
/// <&UserId>::try_from("@carl:example.com").unwrap(),
/// "@carl:example.com"
/// );
/// ``` /// ```
#[repr(transparent)] #[repr(transparent)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(PartialEq, Eq, PartialOrd, Ord, Hash)]
@ -115,7 +112,8 @@ impl UserId {
/// ///
/// let message = format!( /// let message = format!(
/// r#"Thanks for the update <a href="{link}">{display_name}</a>."#, /// r#"Thanks for the update <a href="{link}">{display_name}</a>."#,
/// link = user_id!("@jplatte:notareal.hs").matrix_to_url(), display_name = "jplatte", /// link = user_id!("@jplatte:notareal.hs").matrix_to_url(),
/// display_name = "jplatte",
/// ); /// );
/// ``` /// ```
pub fn matrix_to_url(&self) -> MatrixToRef<'_> { pub fn matrix_to_url(&self) -> MatrixToRef<'_> {

View File

@ -31,8 +31,10 @@ use val_or_vec::ValOrVec;
/// ///
/// assert_eq!( /// assert_eq!(
/// ruma_serde::urlencoded::from_bytes::<Vec<(String, String)>>( /// ruma_serde::urlencoded::from_bytes::<Vec<(String, String)>>(
/// b"bread=baguette&cheese=comt%C3%A9&meat=ham&fat=butter"), /// b"bread=baguette&cheese=comt%C3%A9&meat=ham&fat=butter"
/// Ok(meal)); /// ),
/// Ok(meal)
/// );
/// ``` /// ```
pub fn from_bytes<'de, T>(input: &'de [u8]) -> Result<T, Error> pub fn from_bytes<'de, T>(input: &'de [u8]) -> Result<T, Error>
where where
@ -53,8 +55,10 @@ where
/// ///
/// assert_eq!( /// assert_eq!(
/// ruma_serde::urlencoded::from_str::<Vec<(String, String)>>( /// ruma_serde::urlencoded::from_str::<Vec<(String, String)>>(
/// "bread=baguette&cheese=comt%C3%A9&meat=ham&fat=butter"), /// "bread=baguette&cheese=comt%C3%A9&meat=ham&fat=butter"
/// Ok(meal)); /// ),
/// Ok(meal)
/// );
/// ``` /// ```
pub fn from_str<'de, T>(input: &'de str) -> Result<T, Error> pub fn from_str<'de, T>(input: &'de str) -> Result<T, Error>
where where

View File

@ -13,16 +13,12 @@ use serde::ser;
/// Serializes a value into a `application/x-www-form-urlencoded` `String` buffer. /// Serializes a value into a `application/x-www-form-urlencoded` `String` buffer.
/// ///
/// ``` /// ```
/// let meal = &[ /// let meal = &[("bread", "baguette"), ("cheese", "comté"), ("meat", "ham"), ("fat", "butter")];
/// ("bread", "baguette"),
/// ("cheese", "comté"),
/// ("meat", "ham"),
/// ("fat", "butter"),
/// ];
/// ///
/// assert_eq!( /// assert_eq!(
/// ruma_serde::urlencoded::to_string(meal), /// ruma_serde::urlencoded::to_string(meal),
/// Ok("bread=baguette&cheese=comt%C3%A9&meat=ham&fat=butter".to_owned())); /// Ok("bread=baguette&cheese=comt%C3%A9&meat=ham&fat=butter".to_owned())
/// );
/// ``` /// ```
pub fn to_string<T: ser::Serialize>(input: T) -> Result<String, Error> { pub fn to_string<T: ser::Serialize>(input: T) -> Result<String, Error> {
let mut urlencoder = UrlEncodedSerializer::new("".to_owned()); let mut urlencoder = UrlEncodedSerializer::new("".to_owned());

View File

@ -116,7 +116,8 @@ static REFERENCE_HASH_FIELDS_TO_REMOVE: &[&str] = &["age_ts", "signatures", "uns
/// let key_pair = ruma_signatures::Ed25519KeyPair::from_der( /// let key_pair = ruma_signatures::Ed25519KeyPair::from_der(
/// &document, /// &document,
/// "1".into(), // The "version" of the key. /// "1".into(), // The "version" of the key.
/// ).unwrap(); /// )
/// .unwrap();
/// ///
/// // Deserialize some JSON. /// // Deserialize some JSON.
/// let mut value = serde_json::from_str("{}").unwrap(); /// let mut value = serde_json::from_str("{}").unwrap();
@ -191,11 +192,10 @@ where
/// # Examples /// # Examples
/// ///
/// ```rust /// ```rust
/// let input = /// let input = r#"{
/// r#"{ /// "本": 2,
/// "本": 2, /// "日": 1
/// "日": 1 /// }"#;
/// }"#;
/// ///
/// let object = serde_json::from_str(input).unwrap(); /// let object = serde_json::from_str(input).unwrap();
/// let canonical = ruma_signatures::canonical_json(&object).unwrap(); /// let canonical = ruma_signatures::canonical_json(&object).unwrap();
@ -430,7 +430,8 @@ pub fn reference_hash(
/// let key_pair = Ed25519KeyPair::from_der( /// let key_pair = Ed25519KeyPair::from_der(
/// &document, /// &document,
/// "1".into(), // The "version" of the key. /// "1".into(), // The "version" of the key.
/// ).unwrap(); /// )
/// .unwrap();
/// ///
/// // Deserialize an event from JSON. /// // Deserialize an event from JSON.
/// let mut object = serde_json::from_str( /// let mut object = serde_json::from_str(
@ -449,8 +450,9 @@ pub fn reference_hash(
/// "unsigned": { /// "unsigned": {
/// "age_ts": 1000000 /// "age_ts": 1000000
/// } /// }
/// }"# /// }"#,
/// ).unwrap(); /// )
/// .unwrap();
/// ///
/// // Hash and sign the JSON with the key pair. /// // Hash and sign the JSON with the key pair.
/// assert!(hash_and_sign_event("domain", &key_pair, &mut object, &RoomVersionId::V1).is_ok()); /// assert!(hash_and_sign_event("domain", &key_pair, &mut object, &RoomVersionId::V1).is_ok());