pub fn new(data: Vec<u8>, mode: PacketMode) -> Result<Packet, Error> {
        let res = unsafe {
            enet_packet_create(
                data.as_ptr() as *const _,
                data.len(),
                mode.to_sys_flags() | _ENetPacketFlag_ENET_PACKET_FLAG_NO_ALLOCATE,
            )
        };

        if res.is_null() {
            return Err(Error(0));
        }

        unsafe {
            (*res).userData = data.capacity() as *mut _;
            (*res).freeCallback = Some(packet_free_callback);
        }

        // we leak the data here, as the enet package has taken ownership of it.
        // The data will be deallocated by packet_free_callback
        std::mem::forget(data);

        Ok(Packet::from_sys_packet(res))
    }
/// Creates a new Packet with optional reliability settings.
///
/// The data is consumed and moved into the enet package without copy.
Creates a new Packet with optional reliability settings.
The data is consumed and moved into the enet package without copy.
Creates a new Packet with optional reliability settings . The data is consumed and moved into the enet package without copy .
pub fn new(data: Vec<u8>, mode: PacketMode) -> Result<Packet, Error> {
        let res = unsafe {
            enet_packet_create(
                data.as_ptr() as *const _,
                data.len(),
                mode.to_sys_flags() | _ENetPacketFlag_ENET_PACKET_FLAG_NO_ALLOCATE,
            )
        };
        if res.is_null() {
            return Err(Error(0));
        }
        unsafe {
            (*res).userData = data.capacity() as *mut _;
            (*res).freeCallback = Some(packet_free_callback);
        }
        // we leak the data here, as the enet package has taken ownership of it.
        // The data will be deallocated by packet_free_callback
        std::mem::forget(data);
        Ok(Packet::from_sys_packet(res))
    }
pub fn new ( data : Vec < u8 > , mode : PacketMode ) -> Result < Packet , Error > { let res = unsafe { enet_packet_create ( data . as_ptr ( ) as * const _ , data . len ( ) , mode . to_sys_flags ( ) | _ENetPacketFlag_ENET_PACKET_FLAG_NO_ALLOCATE , ) } ; if res . is_null ( ) { return Err ( Error ( 0 ) ) ; } unsafe { ( * res ) . userData = data . capacity ( ) as * mut _ ; ( * res ) . freeCallback = Some ( packet_free_callback ) ; } // we leak the data here, as the enet package has taken ownership of it. // The data will be deallocated by packet_free_callback std :: mem :: forget ( data ) ; Ok ( Packet :: from_sys_packet ( res ) ) }
Creates a new Packet with optional reliability settings.
Creates a new Packet with optional reliability settings .
data
Vec<u8>
mode
PacketMode
data
Vec<u8>
mode
PacketMode