cpu-endian

Crates.iocpu-endian
lib.rscpu-endian
version0.1.1
sourcesrc
created_at2020-12-10 11:47:30.958414
updated_at2020-12-10 15:29:46.424565
description`cpu-endian` is a portable crate to detect CPU byte order. It detects how CPU native scalar type is ordered; little-endian or big-endian, or something else (like PDP-endian, mixed-endian, middle-endian, and so on.)
homepage
repositoryhttps://github.com/wbcchsyn/rust-cpu-endian.git
max_upload_size
id321480
size964,388
wbcchsyn (wbcchsyn)

documentation

https://wbcchsyn.github.io/rust-cpu-endian/cpu_endian/index.html

README

cpu-endian

cpu-endian is a portable crate to detect CPU byte order.

It detects how CPU native scalar type is ordered; little-endian or big-endian, or something else (like PDP-endian, mixed-endian, middle-endian, and so on.)

Examples

use cpu_endian::{Endian, working};

// Takes first octet of 0x00ff: u16.
let v: u16 = 0x00ff;
let first_octet: u8 = unsafe {
    let ptr = &v as *const u16;
    let ptr = ptr as *const u8;
    *ptr
};

// If the byte-order is little-endian, the first octet should be 0xff, or if big-endian,
// it should be 0x00.
match working() {
    Endian::Little => assert_eq!(0xff, first_octet),
    Endian::Big => assert_eq!(0x00, first_octet),
    _ => {},
}

Requirements

If the CPU is neither x86 nor x86_64 , C++ compiler with feature c++20 is required.

Commit count: 25

cargo fmt