pub struct ExternalPid {
pub node: Atom,
pub id: u32,
pub serial: u32,
pub creation: u32,
pub local_ext_bytes: Option<Bytes>,
}Expand description
Represents an Erlang PID originating from a remote node. These are easy to get wrong when encoding and decoding due to the special LOCAL_EXT encoding.
When a PID is received via LOCAL_EXT, the original raw bytes are preserved
in local_ext_bytes to allow for transparent re-encoding when sending the
PID back to the remote node. LOCAL_EXT contains an opaque 8-byte hash that
cannot be reconstructed from the parsed fields.
NEW_PID_EXT does NOT need raw bytes preserved because it can be exactly reconstructed from (node, id, serial, creation).
N.B.: the local_ext_bytes field is excluded from equality, hash, and ordering
comparisons as it is nothing but an implementation detail. Two PIDs are equal
if their (node, id, serial, creation) match, regardless of how they were encoded.
Fields§
§node: Atom§id: u32§serial: u32§creation: u32§local_ext_bytes: Option<Bytes>If this PID was decoded from LOCAL_EXT, this contains the hash (8 bytes) and nested term bytes for transparent re-encoding.
Bytes offer zero-copy cloning.
Implementations§
Source§impl ExternalPid
impl ExternalPid
pub fn new(node: Atom, id: u32, serial: u32, creation: u32) -> ExternalPid
Sourcepub fn with_local_ext_bytes(
node: Atom,
id: u32,
serial: u32,
creation: u32,
local_ext_bytes: impl Into<Bytes>,
) -> ExternalPid
pub fn with_local_ext_bytes( node: Atom, id: u32, serial: u32, creation: u32, local_ext_bytes: impl Into<Bytes>, ) -> ExternalPid
Creates a new PID with preserved LOCAL_EXT bytes.
Accepts any type that can be converted to Bytes (e.g., Vec<u8>, &[u8], Bytes).
Sourcepub fn is_local_ext(&self) -> bool
pub fn is_local_ext(&self) -> bool
Returns true if this PID was decoded from LOCAL_EXT format.
pub fn from_string( node: Atom, pid_str: &str, ) -> Result<ExternalPid, DecodeError>
pub fn to_erl_pid_string(&self) -> String
Sourcepub fn from_erl_pid_string(
node: Atom,
pid_str: &str,
creation: u32,
) -> Result<ExternalPid, DecodeError>
pub fn from_erl_pid_string( node: Atom, pid_str: &str, creation: u32, ) -> Result<ExternalPid, DecodeError>
Parses a PID string in the format used by erlang:pid_to_list/1: <0.{id}.{serial}>.
This is the format returned by to_erl_pid_string.
The node and creation must be passed in because they cannot be inferred from the input.
pub fn to_charlist_term(&self) -> OwnedTerm
Trait Implementations§
Source§impl Clone for ExternalPid
impl Clone for ExternalPid
Source§fn clone(&self) -> ExternalPid
fn clone(&self) -> ExternalPid
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more