Skip to main content

Jid

Struct Jid 

Source
pub struct Jid {
    pub user: CompactString,
    pub server: Server,
    pub agent: u8,
    pub device: u16,
    pub integrator: u16,
}

Fields§

§user: CompactString§server: Server§agent: u8§device: u16§integrator: u16

Implementations§

Source§

impl Jid

Source

pub fn new(user: impl Into<CompactString>, server: Server) -> Self

Source

pub fn pn(user: impl Into<CompactString>) -> Self

Create a phone number JID (s.whatsapp.net)

Source

pub fn lid(user: impl Into<CompactString>) -> Self

Create a LID JID (lid server)

Source

pub fn status_broadcast() -> Self

Creates the status@broadcast JID used for status/story updates.

Source

pub fn group(id: impl Into<CompactString>) -> Self

Create a group JID (g.us).

Source

pub fn newsletter(id: impl Into<CompactString>) -> Self

Create a newsletter (channel) JID (newsletter server).

Source

pub fn pn_device(user: impl Into<CompactString>, device: u16) -> Self

Create a phone number JID with device ID

Source

pub fn lid_device(user: impl Into<CompactString>, device: u16) -> Self

Create a LID JID with device ID

Source

pub fn is_pn(&self) -> bool

Returns true if this is a Phone Number based JID (s.whatsapp.net)

Source

pub fn is_lid(&self) -> bool

Returns true if this is a LID based JID

Source

pub fn user_base(&self) -> &str

Returns the user part without the device ID suffix (e.g., “123:4” -> “123”)

Source

pub fn with_device(&self, device_id: u16) -> Self

Helper to construct a specific device JID from this one

Source

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.

Source

pub fn to_non_ad(&self) -> Self

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn display_eq(&self, other: &str) -> bool

Compare the display representation with other without allocating.

Source

pub fn display_eq_jid(&self, other: &Self) -> bool

Compare two JIDs by the representation emitted by fmt::Display.

Source

pub fn device_eq(&self, other: &Jid) -> bool

Compare device identity (user, server, device) without allocation.

Source

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.

Source

pub fn device_key(&self) -> DeviceKey<'_>

Get a borrowing key for O(1) HashSet lookups by device identity.

Source§

impl Jid

Source

pub fn observe(&self) -> ObservedJid<'_>

Privacy-aware display for tracing spans/fields. See ObservedJid.

Trait Implementations§

Source§

impl Clone for Jid

Source§

fn clone(&self) -> Jid

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Jid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Jid

Source§

fn default() -> Jid

Returns the “default value” for a type. Read more
Source§

impl Display for Jid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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.

Source§

fn from(jid: &Jid) -> Self

Converts to this type from the input type.
Source§

impl From<&Jid> for NodeValue

Source§

fn from(jid: &Jid) -> Self

Converts to this type from the input type.
Source§

impl From<Jid> for String

Source§

fn from(jid: Jid) -> Self

Converts to this type from the input type.
Source§

impl From<Jid> for NodeValue

Source§

fn from(jid: Jid) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Jid

Source§

type Err = JidError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Jid

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl JidExt for Jid

Source§

fn user(&self) -> &str

Source§

fn server(&self) -> Server

Source§

fn device(&self) -> u16

Source§

fn integrator(&self) -> u16

Source§

fn is_ad(&self) -> bool

Source§

fn is_interop(&self) -> bool

Source§

fn is_messenger(&self) -> bool

Source§

fn is_group(&self) -> bool

Source§

fn is_broadcast_list(&self) -> bool

Source§

fn is_status_broadcast(&self) -> bool

Source§

fn is_psa(&self) -> bool

The system/announcements account (0@s.whatsapp.net / 0@c.us). It never answers user-directed IQs, so requests must be short-circuited client-side (WA Web excludes it via isPSA before hitting the server).
Source§

fn is_bot(&self) -> bool

Source§

fn is_newsletter(&self) -> bool

Source§

fn is_hosted(&self) -> bool

Returns true if this is a hosted/Cloud API device. Hosted devices have device ID 99 or use @hosted/@hosted.lid server. These devices should be excluded from group message fanout.
Source§

fn is_empty(&self) -> bool

Source§

fn is_same_user_as(&self, other: &impl JidExt) -> bool

Source§

impl PartialEq for Jid

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<Jid> for JidRef<'_>

Source§

fn eq(&self, other: &Jid) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<JidRef<'_>> for Jid

Source§

fn eq(&self, other: &JidRef<'_>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl TryFrom<String> for Jid

Source§

type Error = JidError

The type returned in the event of a conversion error.
Source§

fn try_from(value: String) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for Jid

§

impl RefUnwindSafe for Jid

§

impl Send for Jid

§

impl Sync for Jid

§

impl Unpin for Jid

§

impl UnsafeUnpin for Jid

§

impl UnwindSafe for Jid

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.