Skip to content

Commit

Permalink
Improve some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
novacrazy committed Nov 17, 2024
1 parent 05727b0 commit 137c213
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ triomphe = "0.1.8"
rustc-hash = { version = "2.0", default-features = false }
const-random = "0.1"

bon = { version = "2", optional = true }
bon = { version = "3", optional = true }
typed-builder = { version = "0.20", optional = true }
schemars = { version = "1.0.0-alpha.14", optional = true, features = ["triomphe01", "smol_str03", "thin-vec02"] }
okapi = { version = "0.7.0-rc.1", optional = true }
Expand Down
7 changes: 6 additions & 1 deletion src/api/commands/party.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ command! { Party;
pub party_id: PartyId,
}

// TODO: Use same command for accepting?
/// Transfer ownership of a party to another user.
///
/// This command is only available to the current owner, or the person who is accepting ownership.
///
/// Confirming ownership is done by the accepting user also sending a `TransferOwnership`
/// command with the same parameters.
+struct TransferOwnership(U) -> One (): PUT("party" / party_id / "owner" / user_id) {
pub party_id: PartyId,
pub user_id: UserId,
Expand Down
19 changes: 19 additions & 0 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,36 @@ pub use self::{
};

/// Directional search query
///
/// Used for paginated queries to determine the direction of the search, where
/// "after" is ascending and "before" is descending, starting from the given ID.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
#[cfg_attr(feature = "ts", derive(ts_bindgen::TypeScriptDef))]
#[serde(rename_all = "lowercase")]
#[must_use]
pub enum Cursor {
/// Select item exactly matching the ID.
Exact(Snowflake),
/// Select ascending items starting from the ID.
After(Snowflake),
/// Select descending items starting from the ID.
Before(Snowflake),
}

impl Cursor {
/// Select ascending items starting from the minimum possible ID.
pub const fn after_min() -> Self {
Cursor::After(Snowflake::null())
}

/// Select descending items starting from the maximum possible ID.
pub const fn before_max() -> Self {
Cursor::Before(Snowflake::max_safe_value())
}
}

#[allow(unused)]
#[inline]
pub(crate) const fn is_false(value: &bool) -> bool {
Expand Down
17 changes: 11 additions & 6 deletions src/models/nullable.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
/// Similar to `Option`, `Undefined` values can be used when data may exist but is not provided.
/// Similar to `Option`, `Undefined` can be used when data may exist but is not provided.
///
/// For example, a user biography may not be provided to any random user if they haven't
/// given permission to non-friends to view their profile, but that does not imply it doesn't exist.
/// Consider using `Nullable` when you want to distinguish between `None` and `Some(None)`,
/// as there is a difference between not providing a value and providing a `null` value.
///
/// Similarly, not all gateway events provide all information in objects. Again, user profiles
/// are notable in that biographies are typically excluded in events to save on bandwidth.
/// This is commonly used when setting a field or property to `null`/`None` versus
/// not changing it all, such as in patch requests where you want to update
/// only certain fields. Additionally, when data is not available to the user due to permissions,
/// it may also be set to `Undefined`. It may still exist, but its state is not known.
///
/// This is not equivalent to three-state boolean logic, and `Undefined` values will
/// be considered equal to each other.
#[must_use = "This enum is used to represent nullable values, and should be used as such"]
#[derive(Default, Debug, Clone, Copy, Hash)]
#[derive(Default, Debug, Clone, Copy, Hash, Eq)]
#[repr(u8)]
pub enum Nullable<T> {
/// Neither present nor absent, an indeterminant value.
Expand Down

0 comments on commit 137c213

Please sign in to comment.