Skip to content

Commit

Permalink
ci: check doc comments with nightly format (#1857)
Browse files Browse the repository at this point in the history
  • Loading branch information
7596ff committed Nov 13, 2022
1 parent 3c43c44 commit b83453f
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 66 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,17 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install nightly toolchain
uses: dtolnay/rust-toolchain@v1
with:
components: rustfmt
toolchain: nightly

- name: Add problem matchers
run: echo "::add-matcher::.github/rust.json"

- name: Run cargo fmt
run: cargo fmt --all -- --check
- name: Check code formatting
run: cargo fmt --all -- --check --unstable-features --config format_code_in_doc_comments=true

min-vers:
name: Minimal crate versions
Expand Down
10 changes: 6 additions & 4 deletions twilight-gateway/src/cluster/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,13 @@ impl ClusterBuilder {
/// ```no_run
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use std::env::{self, consts::OS};
/// use twilight_gateway::{Intents, Cluster};
/// use twilight_gateway::{Cluster, Intents};
/// use twilight_model::gateway::payload::outgoing::identify::IdentifyProperties;
///
/// let token = env::var("DISCORD_TOKEN")?;
/// let properties = IdentifyProperties::new("twilight.rs", "twilight.rs", OS);
///
/// let builder = Cluster::builder(token, Intents::empty())
/// .identify_properties(properties);
/// let builder = Cluster::builder(token, Intents::empty()).identify_properties(properties);
/// # Ok(()) }
/// ```
#[allow(clippy::missing_const_for_fn)]
Expand Down Expand Up @@ -273,8 +272,11 @@ impl ClusterBuilder {
/// Configure a cluster to manage shards 0-9 out of 20 shards total:
///
/// ```no_run
/// use twilight_gateway::{cluster::{Cluster, ShardScheme}, Intents};
/// use std::env;
/// use twilight_gateway::{
/// cluster::{Cluster, ShardScheme},
/// Intents,
/// };
///
/// # #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let token = env::var("DISCORD_TOKEN")?;
Expand Down
39 changes: 18 additions & 21 deletions twilight-gateway/src/cluster/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,21 @@ impl Cluster {
/// Create a cluster, receiving a stream of events:
///
/// ```no_run
/// use twilight_gateway::{Cluster, EventTypeFlags, Event, Intents};
/// use futures::StreamExt;
/// use std::env;
/// use twilight_gateway::{Cluster, Event, EventTypeFlags, Intents};
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let types = EventTypeFlags::MESSAGE_CREATE
/// | EventTypeFlags::MESSAGE_DELETE
/// | EventTypeFlags::MESSAGE_UPDATE;
///
/// let (cluster, mut events) = Cluster::builder(env::var("DISCORD_TOKEN")?, Intents::GUILD_MESSAGES)
/// .event_types(types)
/// .build()
/// .await?;
/// let (cluster, mut events) =
/// Cluster::builder(env::var("DISCORD_TOKEN")?, Intents::GUILD_MESSAGES)
/// .event_types(types)
/// .build()
/// .await?;
/// cluster.up().await;
///
/// while let Some((shard_id, event)) = events.next().await {
Expand All @@ -253,7 +254,7 @@ impl Cluster {
/// Event::MessageDelete(_) => println!("Shard {shard_id} got a deleted message"),
/// Event::MessageUpdate(_) => println!("Shard {shard_id} got an updated message"),
/// // No other events will come in through the stream.
/// _ => {},
/// _ => {}
/// }
/// }
/// # Ok(()) }
Expand Down Expand Up @@ -327,9 +328,9 @@ impl Cluster {
/// created, deleted, or updated:
///
/// ```no_run
/// use twilight_gateway::{Cluster, EventTypeFlags, Event, Intents};
/// use futures::StreamExt;
/// use std::env;
/// use twilight_gateway::{Cluster, Event, EventTypeFlags, Intents};
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -350,7 +351,7 @@ impl Cluster {
/// Event::MessageDelete(_) => println!("Shard {shard_id} got a deleted message"),
/// Event::MessageUpdate(_) => println!("Shard {shard_id} got an updated message"),
/// // No other events will come in through the stream.
/// _ => {},
/// _ => {}
/// }
/// }
/// # Ok(()) }
Expand All @@ -372,8 +373,11 @@ impl Cluster {
/// Bring up a cluster, starting shards all 10 shards that a bot uses:
///
/// ```no_run
/// use twilight_gateway::{cluster::{Cluster, ShardScheme}, Intents};
/// use std::env;
/// use twilight_gateway::{
/// cluster::{Cluster, ShardScheme},
/// Intents,
/// };
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand Down Expand Up @@ -435,8 +439,8 @@ impl Cluster {
/// After waiting a minute, print the ID, latency, and stage of each shard:
///
/// ```no_run
/// use twilight_gateway::{Cluster, Intents};
/// use std::{env, time::Duration};
/// use twilight_gateway::{Cluster, Intents};
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand Down Expand Up @@ -472,11 +476,9 @@ impl Cluster {
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use std::env;
/// use twilight_gateway::{cluster::Cluster, Intents};
/// use twilight_model::{
/// gateway::{
/// payload::outgoing::UpdatePresence,
/// presence::{Activity, ActivityType, MinimalActivity, Status},
/// },
/// use twilight_model::gateway::{
/// payload::outgoing::UpdatePresence,
/// presence::{Activity, ActivityType, MinimalActivity, Status},
/// };
///
/// let intents = Intents::GUILD_VOICE_STATES;
Expand All @@ -494,12 +496,7 @@ impl Cluster {
/// name: "testing".to_owned(),
/// url: None,
/// });
/// let request = UpdatePresence::new(
/// Vec::from([activity]),
/// false,
/// None,
/// Status::Online,
/// )?;
/// let request = UpdatePresence::new(Vec::from([activity]), false, None, Status::Online)?;
///
/// // Send the request over the shard.
/// cluster.command(2, &request).await?;
Expand Down
17 changes: 9 additions & 8 deletions twilight-gateway/src/cluster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
//! disconnected, and when new message commands come in:
//!
//! ```no_run
//! use twilight_gateway::{Cluster, Event, Intents};
//! use futures::StreamExt;
//! use std::{env, sync::Arc};
//! use twilight_gateway::{Cluster, Event, Intents};
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//! let token = env::var("DISCORD_TOKEN")?;
//! let intents = Intents::GUILD_BANS | Intents::GUILD_EMOJIS_AND_STICKERS | Intents::GUILD_MESSAGES;
//! let intents =
//! Intents::GUILD_BANS | Intents::GUILD_EMOJIS_AND_STICKERS | Intents::GUILD_MESSAGES;
//! let (cluster, mut events) = Cluster::new(token, intents).await?;
//! let cluster = Arc::new(cluster);
//! cluster.up().await;
Expand All @@ -32,23 +33,23 @@
//! match event {
//! Event::ShardConnected { .. } => {
//! println!("Shard {shard_id} is now connected");
//! },
//! }
//! Event::ShardDisconnected { .. } => {
//! println!("Shard {shard_id} is now disconnected");
//! },
//! }
//! Event::MessageCreate(msg) if msg.content == "!latency" => {
//! if let Some(shard) = cluster.shard(shard_id) {
//! if let Ok(info) = shard.info() {
//! println!("Shard {shard_id}'s latency is {:?}", info.latency());
//! }
//! }
//! },
//! }
//! Event::MessageCreate(msg) if msg.content == "!shutdown" => {
//! println!("Got a shutdown request from shard {shard_id}");
//!
//! cluster.down();
//! },
//! _ => {},
//! }
//! _ => {}
//! }
//! }
//! ```
Expand All @@ -57,9 +58,9 @@
//! of 16:
//!
//! ```no_run
//! use twilight_gateway::{cluster::ShardScheme, Cluster, Event, Intents};
//! use futures::StreamExt;
//! use std::env;
//! use twilight_gateway::{cluster::ShardScheme, Cluster, Event, Intents};
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
Expand Down
17 changes: 9 additions & 8 deletions twilight-gateway/src/shard/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ impl ShardBuilder {
/// let token = env::var("DISCORD_TOKEN")?;
/// let properties = IdentifyProperties::new("twilight.rs", "twilight.rs", OS);
///
/// let builder = Shard::builder(token, Intents::empty())
/// .identify_properties(properties);
/// let builder = Shard::builder(token, Intents::empty()).identify_properties(properties);
/// # Ok(()) }
/// ```
#[allow(clippy::missing_const_for_fn)]
Expand Down Expand Up @@ -264,8 +263,8 @@ impl ShardBuilder {
/// };
///
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let shard = Shard::builder(env::var("DISCORD_TOKEN")?, Intents::empty())
/// .presence(UpdatePresencePayload::new(
/// let shard = Shard::builder(env::var("DISCORD_TOKEN")?, Intents::empty()).presence(
/// UpdatePresencePayload::new(
/// vec![MinimalActivity {
/// kind: ActivityType::Playing,
/// name: "Not accepting commands".into(),
Expand All @@ -275,9 +274,9 @@ impl ShardBuilder {
/// false,
/// None,
/// Status::Idle,
/// )?);
/// )?,
/// );
/// # Ok(()) }
///
/// ```
pub fn presence(mut self, presence: UpdatePresencePayload) -> Self {
self.presence.replace(presence);
Expand Down Expand Up @@ -333,13 +332,15 @@ impl ShardBuilder {
/// a total of 19 shards:
///
/// ```no_run
/// use twilight_gateway::{Intents, Shard};
/// use std::env;
/// use twilight_gateway::{Intents, Shard};
///
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let token = env::var("DISCORD_TOKEN")?;
///
/// let shard = Shard::builder(token, Intents::empty()).shard(18, 19)?.build();
/// let shard = Shard::builder(token, Intents::empty())
/// .shard(18, 19)?
/// .build();
/// # Ok(()) }
/// ```
///
Expand Down
15 changes: 9 additions & 6 deletions twilight-gateway/src/shard/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ pub struct ResumeSession {
/// ```no_run
/// use futures::stream::StreamExt;
/// use std::env;
/// use twilight_gateway::{EventTypeFlags, Event, Intents, Shard};
/// use twilight_gateway::{Event, EventTypeFlags, Intents, Shard};
///
/// # #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// // Use the value of the "DISCORD_TOKEN" environment variable as the bot's
Expand All @@ -390,11 +390,11 @@ pub struct ResumeSession {
/// match event {
/// Event::MessageCreate(message) => {
/// println!("message received with content: {}", message.content);
/// },
/// }
/// Event::MessageDelete(message) => {
/// println!("message with ID {} deleted", message.id);
/// },
/// _ => {},
/// }
/// _ => {}
/// }
/// }
/// # Ok(()) }
Expand All @@ -421,9 +421,9 @@ impl Shard {
/// current connection stage:
///
/// ```no_run
/// use twilight_gateway::{Intents, Shard};
/// use std::{env, time::Duration};
/// use tokio::time as tokio_time;
/// use twilight_gateway::{Intents, Shard};
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand Down Expand Up @@ -639,7 +639,10 @@ impl Shard {
/// ```no_run
/// # #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use std::env;
/// use twilight_gateway::{shard::{raw_message::Message, Shard}, Intents};
/// use twilight_gateway::{
/// shard::{raw_message::Message, Shard},
/// Intents,
/// };
///
/// let token = env::var("DISCORD_TOKEN")?;
/// let (shard, _) = Shard::new(token, Intents::GUILDS);
Expand Down
9 changes: 2 additions & 7 deletions twilight-gateway/src/shard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
//! # #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use std::env;
//! use twilight_gateway::{shard::Shard, Intents};
//! use twilight_model::{
//! gateway::payload::outgoing::RequestGuildMembers,
//! id::Id,
//! };
//! use twilight_model::{gateway::payload::outgoing::RequestGuildMembers, id::Id};
//!
//! let intents = Intents::GUILD_MEMBERS;
//! let token = env::var("DISCORD_TOKEN")?;
Expand All @@ -35,9 +32,7 @@
//!
//! // Query members whose names start with "tw" and limit the results to
//! // 10 members.
//! let request =
//! RequestGuildMembers::builder(Id::new(1))
//! .query("tw", Some(10));
//! let request = RequestGuildMembers::builder(Id::new(1)).query("tw", Some(10));
//!
//! // Send the request over the shard.
//! shard.command(&request).await?;
Expand Down
4 changes: 2 additions & 2 deletions twilight-http/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2183,7 +2183,7 @@ impl Client {
///
/// ```no_run
/// # use twilight_http::Client;
/// use twilight_model::{id::Id, guild::scheduled_event::PrivacyLevel, util::Timestamp};
/// use twilight_model::{guild::scheduled_event::PrivacyLevel, id::Id, util::Timestamp};
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// # let client = Client::new("token".to_owned());
Expand All @@ -2208,7 +2208,7 @@ impl Client {
///
/// ```no_run
/// # use twilight_http::Client;
/// use twilight_model::{id::Id, guild::scheduled_event::PrivacyLevel, util::Timestamp};
/// use twilight_model::{guild::scheduled_event::PrivacyLevel, id::Id, util::Timestamp};
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// # let client = Client::new("token".to_owned());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use twilight_model::id::{marker::ApplicationMarker, Id};
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use std::env;
/// use twilight_http::{Client, request::AuditLogReason};
/// use twilight_http::{request::AuditLogReason, Client};
/// use twilight_model::id::Id;
///
/// let client = Client::new(env::var("DISCORD_TOKEN")?);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use twilight_model::{
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use std::env;
/// use twilight_http::{Client, request::AuditLogReason};
/// use twilight_http::{request::AuditLogReason, Client};
/// use twilight_model::id::Id;
///
/// let client = Client::new(env::var("DISCORD_TOKEN")?);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use twilight_model::{
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use std::env;
/// use twilight_http::{Client, request::AuditLogReason};
/// use twilight_http::{request::AuditLogReason, Client};
/// use twilight_model::id::Id;
///
/// let client = Client::new(env::var("DISCORD_TOKEN")?);
Expand Down
Loading

0 comments on commit b83453f

Please sign in to comment.