pub unsafe fn read_isize_ne(bytes: &[u8]) -> isizeExpand description
Unsafe, near zero cost transmutation of a byte array slice into an isize integer using native-endianness.
§Safety
To make it “safe” and does not cause memory errors, you must ensure the input has at least isize’d bytes prior to calling this.
§Arguments
bytes: the byte array reference
returns: isize
§Examples
use hyper_byte::read_isize_ne;
let slice = [0u8; 16];
// PERFECTLY SAFE
let first_value = unsafe { read_isize_ne(&slice[0..size_of::<isize>()]) };
// NOT SAFE
let second_value = unsafe { read_isize_ne(&slice[9..9]) };
pub fn read_isize_safe_be(array: &[u8], index: &mut usize) -> isize {
// "SAFE" because even if the array is not of this length,
// it will still at least panic and not cause undefined behaviour
let third_value = unsafe { read_isize_ne(&array[*index..(*index+size_of::<isize>())]) };
*index += size_of::<isize>();
third_value
}