Trait ext_php_rs::binary::Pack

source ·
pub unsafe trait Pack: Clone {
    // Required methods
    fn pack_into(vec: Vec<Self>) -> *mut zend_string;
    fn unpack_into(s: &zend_string) -> Vec<Self>;
}
Expand description

Used to convert between Zend binary strings and vectors. Useful in conjunction with the pack and unpack functions built-in to PHP.

§Safety

The types cannot be ensured between PHP and Rust, as the data is represented as a string when crossing the language boundary. Exercise caution when using these functions.

Required Methods§

source

fn pack_into(vec: Vec<Self>) -> *mut zend_string

Packs a given vector into a Zend binary string. Can be passed to PHP and then unpacked using the unpack function.

§Parameters
  • vec - The vector to pack into a binary string.
source

fn unpack_into(s: &zend_string) -> Vec<Self>

Unpacks a given Zend binary string into a Rust vector. Can be used to pass data from pack in PHP to Rust without encoding into another format. Note that the data must be all one type, as this implementation only unpacks one type.

§Safety

There is no way to tell if the data stored in the string is actually of the given type. The results of this function can also differ from platform-to-platform due to the different representation of some types on different platforms. Consult the pack function documentation for more details.

§Parameters
  • s - The Zend string containing the binary data.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Pack for f32

source§

impl Pack for f64

source§

impl Pack for i8

source§

impl Pack for i16

source§

impl Pack for i32

source§

impl Pack for i64

source§

impl Pack for isize

source§

impl Pack for u8

source§

impl Pack for u16

source§

impl Pack for u32

source§

impl Pack for u64

source§

impl Pack for usize

Implementors§