vm_memory/
endian.rs

1// Copyright 2017 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE-BSD-3-Clause file.
4//
5// SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
6
7//! Explicit endian types useful for embedding in structs or reinterpreting data.
8//!
9//! Each endian type is guaarnteed to have the same size and alignment as a regular unsigned
10//! primitive of the equal size.
11//!
12//! # Examples
13//!
14//! ```
15//! # use vm_memory::{Be32, Le32};
16//! #
17//! let b: Be32 = From::from(3);
18//! let l: Le32 = From::from(3);
19//!
20//! assert_eq!(b.to_native(), 3);
21//! assert_eq!(l.to_native(), 3);
22//! assert!(b == 3);
23//! assert!(l == 3);
24//!
25//! let b_trans: u32 = unsafe { std::mem::transmute(b) };
26//! let l_trans: u32 = unsafe { std::mem::transmute(l) };
27//!
28//! #[cfg(target_endian = "little")]
29//! assert_eq!(l_trans, 3);
30//! #[cfg(target_endian = "big")]
31//! assert_eq!(b_trans, 3);
32//!
33//! assert_ne!(b_trans, l_trans);
34//! ```
35
36pub use vm_memory_new::endian::{Be16, Be32, Be64, BeSize, Le16, Le32, Le64, LeSize};