[][src]Enum data_models::DataModel

pub enum DataModel {
    IP16,
    IP16L32,
    LP32,
    ILP32,
    LLP64,
    LP64,
    ILP64,
    SILP64,
    Unknown,
}

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

  1. J. R. Mashey. The long road to 64 bits. ACM Queue Magazine, 4(8):24–35, 1996.
  2. T. Lauer. Porting to Win32: A Guide to Making Your Applications Ready for the 32-Bit Future of Windows. Springer, 1996.

Variants

IP16

16-bit integer and pointer (16-bit PDP-11)

IP16L32

16-bit integer and pointer and 32-bit long (32-bit PDP-11)

LP32

16-bit integer, and 32-bit long and pointer (m68k Mac & win16).

ILP32

32-bit integer, long, and pointer (Unix and Unix-like before mid-1990s & win32).

LLP64

32-bit integer, long, and 64-bit pointer (windows after XP).

LP64

32-bit integer, 64-bit long and pointer (Unix/Linux after the 1990s).

ILP64

64-bit integer, long and pointer (SPARC64 from hal/fujitsu I think).

SILP64

64-bit short, integer, long and pointer (UNICOS from Cray).

Unknown

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.