Skip to content

Commit dba4fa6

Browse files
authored
Improve some docs (#3027)
Improved wording and removed some sentences that are no longer relevant. These docs are mostly the ones that were touched by #2988.
1 parent 99ce95b commit dba4fa6

File tree

7 files changed

+36
-34
lines changed

7 files changed

+36
-34
lines changed

src/gateway/client/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use crate::gateway::{ActivityData, ShardMessenger, ShardRunner};
77
use crate::http::Http;
88
use crate::model::prelude::*;
99

10-
/// The context is a general utility struct provided on event dispatches.
10+
/// A general utility struct provided on event dispatches.
1111
///
12-
/// The Context helps with dealing with the current "context" of the event dispatch. The context
13-
/// also acts as a general high-level interface over the associated [`Shard`] which received
14-
/// the event, or the low-level [`http`] module.
12+
/// The [`Context`] helps with dealing with the current "context" of the event dispatch. It also
13+
/// acts as a general high-level interface over the low-level [`http`] module, plus the associated
14+
/// [`Shard`] which received the event.
1515
///
1616
/// The context contains "shortcuts", like for interacting with the shard. Methods like
1717
/// [`Self::set_activity`] will unlock the shard and perform an update for you to save a bit of

src/gateway/client/event_handler.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ macro_rules! event_handler {
3030
}
3131
)*
3232

33-
/// Checks if the `event` should be dispatched (`true`) or ignored (`false`).
33+
/// Checks if the `event` should be dispatched or ignored. Returns `true` by default.
3434
///
35-
/// This affects [`crate::collector::collect`], [`crate::framework::Framework::dispatch`] and this `EventHandler` trait.
35+
/// Returning `false` will drop an event and prevent it being dispatched by any
36+
/// frameworks and will exclude it from any collectors.
3637
///
3738
/// ## Warning
3839
///
@@ -508,10 +509,10 @@ pub trait RawEventHandler: Send + Sync {
508509
/// Dispatched when any event occurs
509510
async fn raw_event(&self, _ctx: Context, _ev: &Event) {}
510511

511-
/// Checks if the `event` should be dispatched (`true`) or ignored (`false`).
512+
/// Checks if the `event` should be dispatched or ignored. Returns `true` by default.
512513
///
513-
/// This affects [`crate::collector::collect`], [`crate::framework::Framework::dispatch`] and
514-
/// this `EventHandler` trait.
514+
/// Returning `false` will drop an event and prevent it being dispatched by any frameworks and
515+
/// will exclude it from any collectors.
515516
///
516517
/// ## Warning
517518
///

src/gateway/client/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,11 @@ impl IntoFuture for ClientBuilder {
343343
}
344344
}
345345

346-
/// A wrapper for HTTP and gateway connections.
346+
/// A high-level client that abstracts over the REST API as well as Discord's gateway.
347347
///
348-
/// The Client is the way to be able to start sending authenticated requests over the REST API, as
349-
/// well as initializing a WebSocket connection through [`Shard`]s. Refer to the [documentation on
350-
/// using sharding][super::sharding] for more information.
348+
/// It enables the user to start sending authenticated HTTP requests, plus also initialize a
349+
/// WebSocket connection to the gateway through [`Shard`]s. Refer to the [documentation on using
350+
/// sharding][super::sharding] for more information.
351351
///
352352
/// # Event Handlers
353353
///

src/gateway/sharding/mod.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Module containing types for gateway sharding.
1+
//! Mechanisms for configuring and managing sharded gateway connections.
22
//!
33
//! Sharding is a method for load-balancing bots across separate threads or processes. Sharding is
44
//! enforced on bots by Discord once they reach a certain number of guilds (2500). Once this
@@ -62,34 +62,31 @@ use crate::model::gateway::{GatewayIntents, ShardInfo};
6262
use crate::model::id::{ApplicationId, GuildId, ShardId};
6363
use crate::model::user::OnlineStatus;
6464

65-
/// A Shard is a higher-level handler for a websocket connection to Discord's gateway.
65+
/// An abstract handler for a websocket connection to Discord's gateway.
6666
///
67-
/// The shard allows for sending and receiving messages over the websocket,
68-
/// such as setting the active activity, reconnecting, syncing guilds, and more.
67+
/// Allows a user to send and receive messages over said websocket, including:
68+
/// * setting the current activity
69+
/// * setting the current online status
70+
/// * receiving gateway events
71+
/// * connection management via heartbeating
6972
///
70-
/// Refer to the [module-level documentation][module docs] for information on effectively using
71-
/// multiple shards, if you need to.
72-
///
73-
/// Note that there are additional methods available if you are manually managing a shard yourself,
74-
/// although they are hidden from the documentation since there are few use cases for doing so.
73+
/// Shard management (including starting, restarting, heartbeating), is performed by the [`Client`]
74+
/// automatically on the user's behalf.
7575
///
7676
/// # Stand-alone shards
7777
///
7878
/// You may instantiate a shard yourself - decoupled from the [`Client`] - by calling
7979
/// [`Shard::new`]. Most use cases will not necessitate this, and unless you're doing something
8080
/// really weird you can just let the client do it for you.
8181
///
82-
/// **Note**: You _really_ do not need to do this. Just call one of the appropriate methods on the
83-
/// [`Client`].
82+
/// **Note**: You _really_ do not need to do this, especially if using multiple shards. Just call
83+
/// one of the appropriate methods on the [`Client`].
8484
///
8585
/// # Examples
8686
///
8787
/// See the documentation for [`Self::new`] on how to use this.
8888
///
8989
/// [`Client`]: crate::Client
90-
/// [`receive`]: #method.receive
91-
/// [docs]: https://discord.com/developers/docs/topics/gateway#sharding
92-
/// [module docs]: crate::gateway#sharding
9390
pub struct Shard {
9491
pub client: WsClient,
9592
presence: PresenceData,

src/http/client.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ where
5959
}
6060
}
6161

62-
/// A builder for the underlying [`Http`] client that performs requests to Discord's HTTP API
62+
/// A builder for the underlying [`Http`] client.
6363
///
6464
/// If you do not need to use a proxy or do not need to disable the rate limiter, you can use
6565
/// [`Http::new`] instead.
@@ -232,6 +232,8 @@ fn reason_into_header(reason: &str) -> Headers {
232232
headers
233233
}
234234

235+
/// A low-level client for sending requests to Discord's HTTP REST API.
236+
///
235237
/// **Note**: For all member functions that return a [`Result`], the Error kind will be either
236238
/// [`Error::Http`] or [`Error::Json`].
237239
#[derive(Debug)]

src/model/guild/member.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,10 @@ pub struct PartialThreadMember {
559559

560560
/// A model representing a user in a Guild Thread.
561561
///
562-
/// [Discord docs](https://discord.com/developers/docs/resources/channel#thread-member-object),
563-
/// [extra fields](https://discord.com/developers/docs/topics/gateway-events#thread-member-update-thread-member-update-event-extra-fields).
562+
/// [Discord docs], [extra fields].
563+
///
564+
/// [Discord docs]: https://discord.com/developers/docs/resources/channel#thread-member-object,
565+
/// [extra fields]: https://discord.com/developers/docs/topics/gateway-events#thread-member-update-thread-member-update-event-extra-fields
564566
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
565567
#[derive(Clone, Debug, Deserialize, Serialize)]
566568
#[non_exhaustive]

src/model/guild/role.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use crate::model::utils::is_false;
1010

1111
/// Information about a role within a guild.
1212
///
13-
/// A role represents a set of permissions, and can be attached to one or multiple users. A role has
14-
/// various miscellaneous configurations, such as being assigned a colour. Roles are unique per
15-
/// guild and do not cross over to other guilds in any way, and can have channel-specific permission
16-
/// overrides in addition to guild-level permissions.
13+
/// A role represents a set of permissions, and can be attached to one or multiple users. A role
14+
/// has various miscellaneous configurations, such as being assigned a colour. Roles are unique per
15+
/// guild and do not cross over to other guilds in any way, and can have channel-specific
16+
/// permission overrides in addition to guild-level permissions.
1717
///
1818
/// [Discord docs](https://discord.com/developers/docs/topics/permissions#role-object).
1919
#[bool_to_bitflags::bool_to_bitflags]

0 commit comments

Comments
 (0)