[−][src]Enum data_models::DataModel
A data model is the choices of bit width of integer types by each platform.
Examples
use data_models::*; let model = DataModel::LP64; // e.g. Linux let p = model.size_of::<Pointer>(); assert_eq!(p, 8);
Background
The C standard defines five base types for integers
- char
- short
- int
- long
- long long
The standard does not specify the exact number of bits for each type. A platform or vendor-dependent data model specifies the exact bit widths.
The names of the models are conventions where the type is signified by a letter and its size; for example, ILP32 would mean (I)nteger, (L)ong, and (P)ointer are 32-bits. Although, make note, the naming scheme is not super consistent.
Four data models found wide acceptance:
-
LP32 or 2/4/4 (int is 16-bit, long and pointer are 32-bit) M68k mac and Win16 API
-
ILP32 or 4/4/4 (int, long, and pointer are 32-bit); Win32 API Unix and Unix-like systems (Linux, Mac OS X)
-
LLP64 or 4/4/8 (int and long are 32-bit, pointer is 64-bit) Win64 API
-
LP64 or 4/8/8 (int is 32-bit, long and pointer are 64-bit) Unix and Unix-like systems (Linux, Mac OS X)
References
- J. R. Mashey. The long road to 64 bits. ACM Queue Magazine, 4(8):24–35, 1996.
- T. Lauer. Porting to Win32: A Guide to Making Your Applications Ready for the 32-Bit Future of Windows. Springer, 1996.
Variants
16-bit integer and pointer (16-bit PDP-11)
16-bit integer and pointer and 32-bit long (32-bit PDP-11)
16-bit integer, and 32-bit long and pointer (m68k Mac & win16).
32-bit integer, long, and pointer (Unix and Unix-like before mid-1990s & win32).
32-bit integer, long, and 64-bit pointer (windows after XP).
32-bit integer, 64-bit long and pointer (Unix/Linux after the 1990s).
64-bit integer, long and pointer (SPARC64 from hal/fujitsu I think).
64-bit short, integer, long and pointer (UNICOS from Cray).
Sentinel value for unknown model.
Implementations
impl DataModel
[src]
pub fn new(int: usize, long: usize, pointer: usize) -> DataModel
[src]
new tries to guess the data model from the byte size of int, long, and pointer.
Example
use data_models::*; let model = DataModel::new(4, 8, 8); // LP64 let p = model.size_of::<Pointer>(); assert_eq!(p, 8);
pub fn size_of<T>(self) -> usize
[src]
size_of will report the size in bytes for one of the types defined in this crate.
Example
use data_models::*; let model = DataModel::LLP64; let p = model.size_of::<Long>(); assert_eq!(p, 4);
Trait Implementations
impl Debug for DataModel
[src]
impl PartialEq<DataModel> for DataModel
[src]
impl StructuralPartialEq for DataModel
[src]
Auto Trait Implementations
impl RefUnwindSafe for DataModel
impl Send for DataModel
impl Sync for DataModel
impl Unpin for DataModel
impl UnwindSafe for DataModel
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,