Skip to main content

PackSlice

Trait PackSlice 

Source
pub unsafe trait PackSlice: Clone {
    // Required method
    unsafe fn unpack_into(s: &zend_string) -> &[Self];
}
Expand description

Used to expose a Zend binary string as a slice. 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

unsafe fn unpack_into(s: &zend_string) -> &[Self]

Creates a Rust slice from a given Zend binary string. 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.

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.

§Safety

The returned slice aliases the string’s bytes, so the caller must guarantee:

  • s.len is a whole multiple of size_of::<Self>().
  • s.val is aligned to align_of::<Self>(). Zend allocates strings on ZEND_MM_ALIGNMENT (8 bytes) boundaries and val sits at an 8-byte offset, but the zend_string type itself only promises 1-byte alignment for val.

Zval::binary_slice performs both checks and is the safe entry point.

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl PackSlice for f32

Source§

unsafe fn unpack_into(s: &zend_string) -> &[Self]

Source§

impl PackSlice for f64

Source§

unsafe fn unpack_into(s: &zend_string) -> &[Self]

Source§

impl PackSlice for i8

Source§

unsafe fn unpack_into(s: &zend_string) -> &[Self]

Source§

impl PackSlice for i16

Source§

unsafe fn unpack_into(s: &zend_string) -> &[Self]

Source§

impl PackSlice for i32

Source§

unsafe fn unpack_into(s: &zend_string) -> &[Self]

Source§

impl PackSlice for i64

Source§

unsafe fn unpack_into(s: &zend_string) -> &[Self]

Source§

impl PackSlice for isize

Source§

unsafe fn unpack_into(s: &zend_string) -> &[Self]

Source§

impl PackSlice for u8

Source§

unsafe fn unpack_into(s: &zend_string) -> &[Self]

Source§

impl PackSlice for u16

Source§

unsafe fn unpack_into(s: &zend_string) -> &[Self]

Source§

impl PackSlice for u32

Source§

unsafe fn unpack_into(s: &zend_string) -> &[Self]

Source§

impl PackSlice for u64

Source§

unsafe fn unpack_into(s: &zend_string) -> &[Self]

Source§

impl PackSlice for usize

Source§

unsafe fn unpack_into(s: &zend_string) -> &[Self]

Implementors§