Skip to main content

Payload

Trait Payload 

Source
pub unsafe trait Payload: Send + 'static {
    // Required methods
    fn into_raw(self) -> (*mut u8, usize);
    unsafe fn from_raw(ptr: *mut u8, len: usize) -> Self;
}
Expand description

An owned byte buffer for an outbound message.

GameNetworkingSockets reads m_pData on its service thread after SendMessages returns, so a message must own its bytes until GameNetworkingSockets releases it.

into_raw returns a (pointer, length) pair that the wrapper stores unchanged in m_pData and m_cbSize. When GameNetworkingSockets releases the message, the wrapper passes those same values to from_raw to rebuild Self, then drops the result.

This mirrors Box::into_raw and Box::from_raw, so you can express how the buffer is freed with an ordinary Rust Drop implementation.

§Safety

from_raw(p, n) must be sound whenever (p, n) came from an earlier into_raw call on the same implementation. In other words, from_raw must undo into_raw exactly.

into_raw must not run the Drop implementation of Self, because ownership passes to GameNetworkingSockets.

Required Methods§

Source

fn into_raw(self) -> (*mut u8, usize)

Source

unsafe fn from_raw(ptr: *mut u8, len: usize) -> Self

§Safety

ptr and len must be the values that an earlier into_raw call on this same implementation returned, and that ownership must not have been reclaimed already.

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 Payload for &'static [u8]

Source§

fn into_raw(self) -> (*mut u8, usize)

Source§

unsafe fn from_raw(ptr: *mut u8, len: usize) -> Self

Source§

impl Payload for &'static str

Source§

fn into_raw(self) -> (*mut u8, usize)

Source§

unsafe fn from_raw(ptr: *mut u8, len: usize) -> Self

Source§

impl Payload for Arc<[u8]>

Source§

fn into_raw(self) -> (*mut u8, usize)

Source§

unsafe fn from_raw(ptr: *mut u8, len: usize) -> Self

Source§

impl Payload for Box<[u8]>

Source§

fn into_raw(self) -> (*mut u8, usize)

Source§

unsafe fn from_raw(ptr: *mut u8, len: usize) -> Self

Source§

impl Payload for String

Source§

fn into_raw(self) -> (*mut u8, usize)

Source§

unsafe fn from_raw(ptr: *mut u8, len: usize) -> Self

Source§

impl Payload for Vec<u8>

Source§

fn into_raw(self) -> (*mut u8, usize)

Source§

unsafe fn from_raw(ptr: *mut u8, len: usize) -> Self

Implementors§