pub struct Jid {
pub user: CompactString,
pub server: Server,
pub agent: u8,
pub device: u16,
pub integrator: u16,
}Fields§
§user: CompactStringInline while it fits in size_of::<String>(): 24 bytes on a 64-bit host,
12 on the wasm32/32-bit builds. Phone, LID and modern group users clear
the wide budget, not the narrow one; a legacy <creator>-<timestamp>
group id clears neither. See tests/jid_identity_alloc.
server: Server§agent: u8§device: u16§integrator: u16Implementations§
Source§impl Jid
impl Jid
pub fn new(user: impl Into<CompactString>, server: Server) -> Self
Sourcepub fn pn(user: impl Into<CompactString>) -> Self
pub fn pn(user: impl Into<CompactString>) -> Self
Create a phone number JID (s.whatsapp.net)
Sourcepub fn lid(user: impl Into<CompactString>) -> Self
pub fn lid(user: impl Into<CompactString>) -> Self
Create a LID JID (lid server)
Sourcepub fn status_broadcast() -> Self
pub fn status_broadcast() -> Self
Creates the status@broadcast JID used for status/story updates.
Sourcepub fn group(id: impl Into<CompactString>) -> Self
pub fn group(id: impl Into<CompactString>) -> Self
Create a group JID (g.us).
Create a newsletter (channel) JID (newsletter server).
Sourcepub fn pn_device(user: impl Into<CompactString>, device: u16) -> Self
pub fn pn_device(user: impl Into<CompactString>, device: u16) -> Self
Create a phone number JID with device ID
Sourcepub fn lid_device(user: impl Into<CompactString>, device: u16) -> Self
pub fn lid_device(user: impl Into<CompactString>, device: u16) -> Self
Create a LID JID with device ID
Sourcepub fn user_base(&self) -> &str
pub fn user_base(&self) -> &str
Returns the user part without the device ID suffix (e.g., “123:4” -> “123”)
Sourcepub fn with_device(&self, device_id: u16) -> Self
pub fn with_device(&self, device_id: u16) -> Self
Helper to construct a specific device JID from this one
Sourcepub fn with_device_hosting(&self, device_id: u16, is_hosted: bool) -> Self
pub fn with_device_hosting(&self, device_id: u16, is_hosted: bool) -> Self
Construct a device JID and select the hosted variant of PN/LID when indicated by a device-list entry.
Non-user namespaces are left unchanged because they have no hosted counterpart on the wire.
pub fn to_non_ad(&self) -> Self
Sourcepub fn to_user_jid(&self) -> Self
pub fn to_user_jid(&self) -> Self
Returns the non-AD user JID representing the account for this JID,
dropping any device/agent and mapping hosted servers to their ordinary
account counterparts (Hosted -> Pn, HostedLid -> Lid).
(Matches WA Web asUserWidOrThrow).
Sourcepub fn into_non_ad(self) -> Self
pub fn into_non_ad(self) -> Self
Consuming to_non_ad: reuses the owned user instead of cloning it.
Prefer this when the receiver is a throwaway owned Jid.
Sourcepub fn is_same_chat_as(&self, other: &Jid) -> bool
pub fn is_same_chat_as(&self, other: &Jid) -> bool
Device-insensitive “same chat” check: two JIDs address the same chat when
they render to the same string ignoring the multi-device device. Compares
user, server, integrator, and agent only where the server renders
the agent (@bot/@interop); Pn/Lid/Hosted suppress it in display, so a
stray decoded agent byte there must not split the chat. Allocates nothing.
Stricter than is_same_user_as, which ignores server.
Sourcepub fn to_non_ad_string(&self) -> String
pub fn to_non_ad_string(&self) -> String
Canonical non-AD string form (user@server, device + agent stripped)
in a single allocation. Equivalent to to_non_ad().to_string() but
skips the throwaway intermediate Jid and its CompactString clone.
Sourcepub fn to_non_ad_arc_str(&self) -> Arc<str> ⓘ
pub fn to_non_ad_arc_str(&self) -> Arc<str> ⓘ
Self::to_non_ad_string as a shareable Arc<str>, in exactly one
allocation. Going through the String first costs two — the buffer, then
the Arc<str> its bytes are copied into — and the message-secret rows
build two of these per message.
Sourcepub fn matches_user_or_lid(&self, user: &Jid, lid: Option<&Jid>) -> bool
pub fn matches_user_or_lid(&self, user: &Jid, lid: Option<&Jid>) -> bool
Check if this JID matches the user or their LID. Useful for checking if a participant is “us” in group messages.
Sourcepub fn to_phash_form_string(&self) -> String
pub fn to_phash_form_string(&self) -> String
See Jid::push_phash_form_to. Not a general JID rendering — use
Display/to_string for that.
Sourcepub fn push_phash_form_to(&self, buf: &mut String)
pub fn push_phash_form_to(&self, buf: &mut String)
Append the form the participant hash is computed over
(user.0:device@server) to buf, for callers that batch many JIDs into
one shared buffer instead of paying a heap String per JID (see
participant_list_hash).
This is not a general-purpose JID rendering. The agent position is
the literal 0, never self.agent, and that is deliberate: WA Web’s
formatFull spelling hardcodes ".0" unconditionally — there is no
per-server carve-out, and WAWebWid has no agent field to read one from.
The server recomputes this exact string to validate the phash, so writing
our agent would mean a rejected hash for any JID that carried one.
If you want the JID as it is addressed, including the agent on the servers
that render it, use Display / Jid::push_to instead.
Sourcepub fn push_to(&self, buf: &mut String)
pub fn push_to(&self, buf: &mut String)
Append the Display representation to buf using direct push operations,
bypassing fmt::Display and dyn Write dispatch.
Sourcepub fn write_display_to<W: Write + ?Sized>(&self, writer: &mut W) -> Result
pub fn write_display_to<W: Write + ?Sized>(&self, writer: &mut W) -> Result
Write the Display representation to any fmt::Write sink without an
intermediate String.
Sourcepub fn display_eq(&self, other: &str) -> bool
pub fn display_eq(&self, other: &str) -> bool
Compare the display representation with other without allocating.
Sourcepub fn display_eq_jid(&self, other: &Self) -> bool
pub fn display_eq_jid(&self, other: &Self) -> bool
Compare two JIDs by the representation emitted by fmt::Display.
Sourcepub fn device_eq(&self, other: &Jid) -> bool
pub fn device_eq(&self, other: &Jid) -> bool
Compare device identity (user, server, device) without allocation.
Sourcepub fn identity_agent(&self) -> u8
pub fn identity_agent(&self) -> u8
The agent as far as identity is concerned: the field itself where the
server renders it (@bot, @interop), 0 where it does not.
Exposed so callers that build their own key over a JID — sorting,
deduplicating, indexing — can key on the same rule == and Hash use
instead of on the raw field, which would split one device in two or, in
reverse, merge two real ones.
Sourcepub fn device_key(&self) -> DeviceKey<'_>
pub fn device_key(&self) -> DeviceKey<'_>
Get a borrowing key for O(1) HashSet lookups by device identity.
Source§impl Jid
impl Jid
Sourcepub fn observe(&self) -> ObservedJid<'_>
pub fn observe(&self) -> ObservedJid<'_>
Privacy-aware display for logs and tracing spans/fields. See ObservedJid.
Trait Implementations§
impl Eq for Jid
Source§impl From<&Jid> for Jid
Lets impl Into<Jid> APIs accept &Jid transparently: borrow-callers pay
one cheap clone (the user part is inline for typical numeric ids), owned
callers move for free.
impl From<&Jid> for Jid
Lets impl Into<Jid> APIs accept &Jid transparently: borrow-callers pay
one cheap clone (the user part is inline for typical numeric ids), owned
callers move for free.
Source§impl JidExt for Jid
impl JidExt for Jid
fn user(&self) -> &str
fn server(&self) -> Server
fn device(&self) -> u16
fn integrator(&self) -> u16
fn is_ad(&self) -> bool
fn is_interop(&self) -> bool
fn is_messenger(&self) -> bool
fn is_group(&self) -> bool
fn is_broadcast_list(&self) -> bool
fn is_status_broadcast(&self) -> bool
Source§fn is_psa(&self) -> bool
fn is_psa(&self) -> bool
0@s.whatsapp.net, however spelled).
It never answers user-directed IQs, so requests must be short-circuited
client-side (WA Web excludes it via isPSA before hitting the server).fn is_bot(&self) -> bool
Source§fn is_hosted(&self) -> bool
fn is_hosted(&self) -> bool
fn is_empty(&self) -> bool
fn is_same_user_as(&self, other: &impl JidExt) -> bool
Auto Trait Implementations§
impl Forget for Jid
impl Freeze for Jid
impl Move for Jid
impl RefUnwindSafe for Jid
impl Send for Jidwhere
Repr: Send,
impl Sync for Jidwhere
Repr: Sync,
impl Unpin for Jid
impl UnsafeUnpin for Jid
impl UnwindSafe for Jid
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more