Skip to main content

Change

From<&Jid> for Jid is now implemented in wacore-binary. All mutating public methods that previously took either Jid (by value) or &Jid (by reference) now take impl Into<Jid> uniformly. This covers the full public surface: send_message, forward_message, send_message_with_options, edit_message, edit_message_encrypted, revoke_message, keep_message, pin_message, unpin_message, send_reaction, and all 53 feature methods across Groups (26), Community (6), Newsletter (2), Presence (1), Polls, Events, Comments, and Reactions.

Before

// Required .clone() to re-use the JID
let result = client.send_message(jid.clone(), msg).await?;
client.revoke_message(jid, &result.message_id, RevokeType::Sender).await?;

// Features took &Jid, core methods took Jid — two conventions on one surface
client.groups().leave(&group_jid).await?;
client.send_message(group_jid, msg).await?; // group_jid now moved

After

// Pass &jid whenever you want to keep it; owned Jid still moves for free
let result = client.send_message(&jid, msg).await?;
client.revoke_message(&jid, &result.message_id, RevokeType::Sender).await?;

// One convention everywhere
client.groups().leave(&group_jid).await?;
client.send_message(&group_jid, msg).await?;

How it works

From<&Jid> for Jid clones the JID. For borrow-callers this is one allocation; for typical phone-number JIDs the user part is stored inline (up to 24 bytes via CompactString), making the clone heap-free. Owned callers continue to move the value at zero cost. Both forms are pinned by the new jid_into_convention compile-time guard in the test suite. Monomorphization discipline: Large async state machines (send_message_with_options, edit_message, edit_message_encrypted, revoke_message) keep a monomorphic _inner behind a thin generic shim that only does .into(), so each Into<Jid> instantiation cannot duplicate the full state machine.

Breaking changes

Pre-1.0 signature change. All converted methods now declare impl Into<Jid> in their public signature.
  • Owned callers (jid by value) — compile unchanged.
  • Borrow callers (&jid) — compile unchanged via From<&Jid>.
  • Trait-object / fn-pointer uses of these inherent methods (e.g. let f: fn(&Client, Jid, ...) = Client::send_message) — need a wrapping closure, since impl Trait parameters are not compatible with concrete fn-pointer types. This is an uncommon pattern for inherent async methods.

Deliberate exceptions

Read-only methods keep &Jid. Converting them would force a clone on every borrow-caller for no benefit. ~59 query methods (query_info, get_metadata, etc.) are unchanged. &[Jid] slices and Option<&Jid> parameters are also out of scope.