From 4bf84c60fd3678664c359ba4c878d89ac52c7778 Mon Sep 17 00:00:00 2001 From: "mintlify[bot]" <109931778+mintlify[bot]@users.noreply.github.com> Date: Sat, 28 Mar 2026 21:49:12 +0000 Subject: [PATCH] docs: update API docs for &[Jid], #[non_exhaustive], and PartialEq/Eq changes Generated-By: mintlify-agent --- api/chatstate.mdx | 3 +++ api/community.mdx | 21 +++++++++++++------ api/groups.mdx | 6 +++++- api/newsletter.mdx | 14 +++++++++++-- api/presence.mdx | 3 +++ api/send.mdx | 7 +++++++ api/status.mdx | 47 ++++++++++++++++++++++-------------------- api/upload.mdx | 3 +++ guides/communities.mdx | 1 + 9 files changed, 74 insertions(+), 31 deletions(-) diff --git a/api/chatstate.mdx b/api/chatstate.mdx index 210b2947..ffa6798e 100644 --- a/api/chatstate.mdx +++ b/api/chatstate.mdx @@ -97,6 +97,7 @@ println!("Cleared typing indicator"); ## ChatStateType Enum ```rust +#[non_exhaustive] pub enum ChatStateType { Composing, // Typing text Recording, // Recording audio @@ -104,6 +105,8 @@ pub enum ChatStateType { } ``` +`ChatStateType` is `#[non_exhaustive]`, so match statements should include a wildcard arm to handle future variants. + **Methods:** - `as_str()` - Returns `"composing"`, `"recording"`, or `"paused"` diff --git a/api/community.mdx b/api/community.mdx index 995d2872..c8046568 100644 --- a/api/community.mdx +++ b/api/community.mdx @@ -275,9 +275,10 @@ for p in &participants { ### CreateCommunityOptions -Options for creating a new community. +Options for creating a new community. Implements `PartialEq` and `Eq`. ```rust +#[derive(Debug, Clone, PartialEq, Eq)] pub struct CreateCommunityOptions { pub name: String, pub description: Option, @@ -301,9 +302,10 @@ let options = CreateCommunityOptions::new("My Community"); ### CreateCommunityResult -Result of creating a community. +Result of creating a community. Implements `PartialEq` and `Eq`. ```rust +#[derive(Debug, Clone, PartialEq, Eq)] pub struct CreateCommunityResult { pub gid: Jid, } @@ -311,9 +313,10 @@ pub struct CreateCommunityResult { ### CommunitySubgroup -A subgroup within a community. +A subgroup within a community. Implements `PartialEq` and `Eq`. ```rust +#[derive(Debug, Clone, PartialEq, Eq)] pub struct CommunitySubgroup { pub id: Jid, pub subject: String, @@ -332,9 +335,10 @@ pub struct CommunitySubgroup { ### LinkSubgroupsResult -Result of linking subgroups to a community. +Result of linking subgroups to a community. Implements `PartialEq` and `Eq`. ```rust +#[derive(Debug, Clone, PartialEq, Eq)] pub struct LinkSubgroupsResult { pub linked_jids: Vec, pub failed_groups: Vec<(Jid, u32)>, @@ -343,9 +347,10 @@ pub struct LinkSubgroupsResult { ### UnlinkSubgroupsResult -Result of unlinking subgroups from a community. +Result of unlinking subgroups from a community. Implements `PartialEq` and `Eq`. ```rust +#[derive(Debug, Clone, PartialEq, Eq)] pub struct UnlinkSubgroupsResult { pub unlinked_jids: Vec, pub failed_groups: Vec<(Jid, u32)>, @@ -354,9 +359,11 @@ pub struct UnlinkSubgroupsResult { ### GroupType -Classification of a group within the community hierarchy. +Classification of a group within the community hierarchy. Implements `PartialEq` and `Eq`. ```rust +#[non_exhaustive] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum GroupType { Default, Community, @@ -366,6 +373,8 @@ pub enum GroupType { } ``` +`GroupType` is `#[non_exhaustive]`, so match statements should include a wildcard arm to handle future variants. + **Variants:** - `Default` — Regular standalone group - `Community` — Community parent group diff --git a/api/groups.mdx b/api/groups.mdx index 6e180371..ea000ba9 100644 --- a/api/groups.mdx +++ b/api/groups.mdx @@ -49,6 +49,8 @@ pub async fn get_participating(&self) -> Result, **Returns:** - `HashMap` - Map of group JID strings to metadata +`GroupMetadata` implements `PartialEq` and `Eq`, allowing direct comparison of group metadata instances. + **GroupMetadata fields:** - `id: Jid` - Group JID - `subject: String` - Group name @@ -75,6 +77,8 @@ pub async fn get_participating(&self) -> Result, See [Community API](/api/community) for community-specific operations. +`GroupParticipant` implements `PartialEq` and `Eq`. + **GroupParticipant fields:** - `jid: Jid` - Participant JID - `phone_number: Option` - Phone number JID (for LID groups) @@ -138,7 +142,7 @@ pub async fn create_group( - `ephemeral_expiration: Option` - Disappearing messages timer in seconds (default: `0`) **Returns:** -- `CreateGroupResult` with `gid: Jid` field +- `CreateGroupResult` with `gid: Jid` field. Implements `PartialEq` and `Eq`. When the `PRIVACY_TOKEN_ON_GROUP_CREATE` AB prop is enabled, the library automatically resolves and attaches privacy tokens (`tc_token`) to each participant during group creation. This is handled internally — you don't need to manage tokens yourself. diff --git a/api/newsletter.mdx b/api/newsletter.mdx index 60292d35..5ab1c333 100644 --- a/api/newsletter.mdx +++ b/api/newsletter.mdx @@ -306,9 +306,10 @@ println!("Subscribed for {}s", duration); ### NewsletterMetadata -Metadata for a newsletter channel. +Metadata for a newsletter channel. Implements `PartialEq` and `Eq` for direct comparison. ```rust +#[derive(Debug, Clone, PartialEq, Eq)] pub struct NewsletterMetadata { pub jid: Jid, pub name: String, @@ -327,6 +328,8 @@ pub struct NewsletterMetadata { ### NewsletterVerification ```rust +#[non_exhaustive] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum NewsletterVerification { Verified, Unverified, @@ -336,6 +339,8 @@ pub enum NewsletterVerification { ### NewsletterState ```rust +#[non_exhaustive] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum NewsletterState { Active, Suspended, @@ -348,6 +353,8 @@ pub enum NewsletterState { The viewer's role in a newsletter. ```rust +#[non_exhaustive] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum NewsletterRole { Owner, Admin, @@ -356,6 +363,8 @@ pub enum NewsletterRole { } ``` +All newsletter enums are `#[non_exhaustive]`, so match statements should include a wildcard arm to handle future variants. + ### NewsletterMessage A message from a newsletter's history. @@ -379,9 +388,10 @@ pub struct NewsletterMessage { ### NewsletterMessageType -The type of a newsletter message. Uses a `StringEnum` for type-safe wire-protocol mapping. +The type of a newsletter message. Uses a `StringEnum` for type-safe wire-protocol mapping. Implements `PartialEq` and `Eq`. ```rust +#[non_exhaustive] pub enum NewsletterMessageType { Text, // "text" Media, // "media" diff --git a/api/presence.mdx b/api/presence.mdx index e161be19..68c550a2 100644 --- a/api/presence.mdx +++ b/api/presence.mdx @@ -119,12 +119,15 @@ println!("Unsubscribed from {}'s presence", contact_jid); ## PresenceStatus Enum ```rust +#[non_exhaustive] pub enum PresenceStatus { Available, // Online Unavailable, // Offline } ``` +`PresenceStatus` is `#[non_exhaustive]`, so match statements should include a wildcard arm to handle future variants. + **Methods:** - `as_str()` - Returns `"available"` or `"unavailable"` diff --git a/api/send.mdx b/api/send.mdx index 2c274190..164c3404 100644 --- a/api/send.mdx +++ b/api/send.mdx @@ -48,6 +48,7 @@ pub async fn send_message( Result of a successfully sent message. Provides the message ID and a convenience method to construct a `MessageKey` for follow-up operations like album child linking. ```rust +#[derive(Debug, Clone, PartialEq, Eq)] pub struct SendResult { pub message_id: String, pub to: Jid, @@ -389,6 +390,7 @@ pub async fn revoke_message( Specifies who is revoking (deleting) the message. ```rust +#[non_exhaustive] pub enum RevokeType { /// The message sender deleting their own message Sender, @@ -398,6 +400,8 @@ pub enum RevokeType { } ``` +`RevokeType` is `#[non_exhaustive]`, so match statements should include a wildcard arm to handle future variants. + Default variant. Use when deleting your own message. Works in both DMs and groups. @@ -474,6 +478,7 @@ pub async fn pin_message( Specifies how long a message stays pinned. Defaults to 7 days (matches WhatsApp Web behavior). ```rust +#[non_exhaustive] pub enum PinDuration { Hours24, Days7, // default @@ -481,6 +486,8 @@ pub enum PinDuration { } ``` +`PinDuration` is `#[non_exhaustive]`, so match statements should include a wildcard arm to handle future variants. + Pin for 24 hours diff --git a/api/status.mdx b/api/status.mdx index cb0079b7..be51f8e2 100644 --- a/api/status.mdx +++ b/api/status.mdx @@ -25,7 +25,7 @@ pub async fn send_text( text: &str, background_argb: u32, font: i32, - recipients: Vec, + recipients: &[Jid], options: StatusSendOptions, ) -> Result ``` @@ -34,7 +34,7 @@ pub async fn send_text( - `text` - Status text content - `background_argb` - Background color as ARGB (e.g., `0xFF1E6E4F`) - `font` - Font style index (0-4) -- `recipients` - List of recipient JIDs +- `recipients` - Slice of recipient JIDs - `options` - Privacy and delivery options **Returns:** @@ -44,7 +44,7 @@ pub async fn send_text( ```rust use whatsapp_rust::{Jid, StatusSendOptions}; -let recipients = vec![ +let recipients = [ Jid::pn("15551234567"), Jid::pn("15559876543"), ]; @@ -54,7 +54,7 @@ let result = client.status() "Hello from Rust!", 0xFF1E6E4F, // Green background 0, // Default font - recipients, + &recipients, StatusSendOptions::default(), ) .await?; @@ -72,7 +72,7 @@ pub async fn send_image( upload: &UploadResponse, thumbnail: Vec, caption: Option<&str>, - recipients: Vec, + recipients: &[Jid], options: StatusSendOptions, ) -> Result ``` @@ -81,7 +81,7 @@ pub async fn send_image( - `upload` - Upload response from `client.upload()` - `thumbnail` - JPEG thumbnail bytes - `caption` - Optional caption text -- `recipients` - List of recipient JIDs +- `recipients` - Slice of recipient JIDs - `options` - Privacy options **Example:** @@ -95,14 +95,12 @@ let upload = client.upload(image_data, MediaType::Image, Default::default()).awa // Create thumbnail (simplified - use proper JPEG encoding) let thumbnail = create_thumbnail(&image_data)?; -let recipients = vec![Jid::pn("15551234567")]; - let result = client.status() .send_image( &upload, thumbnail, Some("Check this out!"), - recipients, + &[Jid::pn("15551234567")], StatusSendOptions::default(), ) .await?; @@ -119,7 +117,7 @@ pub async fn send_video( thumbnail: Vec, duration_seconds: u32, caption: Option<&str>, - recipients: Vec, + recipients: &[Jid], options: StatusSendOptions, ) -> Result ``` @@ -129,7 +127,7 @@ pub async fn send_video( - `thumbnail` - JPEG thumbnail bytes - `duration_seconds` - Video duration - `caption` - Optional caption text -- `recipients` - List of recipient JIDs +- `recipients` - Slice of recipient JIDs - `options` - Privacy options **Example:** @@ -140,15 +138,13 @@ let video_data = std::fs::read("video.mp4")?; let upload = client.upload(video_data, MediaType::Video, Default::default()).await?; let thumbnail = extract_video_thumbnail(&video_data)?; -let recipients = vec![Jid::pn("15551234567")]; - let result = client.status() .send_video( &upload, thumbnail, 30, // 30 seconds None, - recipients, + &[Jid::pn("15551234567")], StatusSendOptions::default(), ) .await?; @@ -162,7 +158,7 @@ Send a custom message type as a status update. pub async fn send_raw( &self, message: wa::Message, - recipients: Vec, + recipients: &[Jid], options: StatusSendOptions, ) -> Result ``` @@ -192,7 +188,7 @@ Delete a previously sent status update. pub async fn revoke( &self, message_id: impl Into, - recipients: Vec, + recipients: &[Jid], options: StatusSendOptions, ) -> Result ``` @@ -206,12 +202,12 @@ pub async fn revoke( ```rust // Send a status let result = client.status() - .send_text("Temporary status", 0xFF000000, 0, recipients.clone(), Default::default()) + .send_text("Temporary status", 0xFF000000, 0, &recipients, Default::default()) .await?; // Later, revoke it client.status() - .revoke(&result.message_id, recipients, Default::default()) + .revoke(&result.message_id, &recipients, Default::default()) .await?; ``` @@ -222,6 +218,7 @@ client.status() Privacy setting for status delivery. ```rust +#[non_exhaustive] pub enum StatusPrivacySetting { /// Send to all contacts in address book (default) Contacts, @@ -232,6 +229,8 @@ pub enum StatusPrivacySetting { } ``` +`StatusPrivacySetting` is `#[non_exhaustive]`, so match statements should include a wildcard arm to handle future variants. + ### StatusSendOptions Options for sending status updates. @@ -288,18 +287,22 @@ let overlay = 0x80000000_u32; ## Recipient management -Recipients should be JIDs of users who can see the status: +Recipients should be JIDs of users who can see the status. You can pass any `&[Jid]` — an array literal, a slice of a `Vec`, or a fixed-size array: ```rust -// Single recipient -let recipients = vec![Jid::pn("15551234567")]; +// Single recipient (array literal) +let recipients = &[Jid::pn("15551234567")]; // Multiple recipients -let recipients = vec![ +let recipients = &[ Jid::pn("15551234567"), Jid::pn("15559876543"), "15557654321@s.whatsapp.net".parse()?, ]; + +// From an existing Vec +let jids = vec![Jid::pn("15551234567")]; +let recipients = &jids; ``` diff --git a/api/upload.mdx b/api/upload.mdx index 7661318a..bf3548df 100644 --- a/api/upload.mdx +++ b/api/upload.mdx @@ -207,12 +207,15 @@ let result = client.send_message(chat_jid, message).await?; Options for customizing upload behavior. ```rust +#[non_exhaustive] pub struct UploadOptions { /// Reuse an existing media key instead of generating a fresh one. pub media_key: Option>, } ``` +`UploadOptions` is `#[non_exhaustive]`, so it cannot be constructed using struct literal syntax from outside the crate. Use `UploadOptions::default()` or `UploadOptions::new()` with builder methods instead. + When set, reuses the provided 32-byte media key instead of generating a new one. This is required when uploading a sticker pack thumbnail, which must share the same `media_key` as the sticker pack ZIP. diff --git a/guides/communities.mdx b/guides/communities.mdx index 94a601f7..114d5aec 100644 --- a/guides/communities.mdx +++ b/guides/communities.mdx @@ -208,6 +208,7 @@ match group_type(&metadata) { GroupType::LinkedAnnouncementGroup => println!("This is the default announcement subgroup"), GroupType::LinkedGeneralGroup => println!("This is the general chat subgroup"), GroupType::Default => println!("This is a regular group"), + _ => println!("Unknown group type"), } ```