#type #c99

no-std stdint

C99 stdint/stdio types for easier interop

3 releases (1 stable)

1.0.0 Jun 3, 2024
0.2.0 Dec 27, 2022
0.1.0 Dec 22, 2022

#364 in Hardware support

Download history 14/week @ 2024-10-11 88/week @ 2024-10-18 2/week @ 2024-10-25 17/week @ 2024-11-01 153/week @ 2024-11-08 169/week @ 2024-11-15 117/week @ 2024-11-22 40/week @ 2024-11-29 204/week @ 2024-12-06 49/week @ 2024-12-13 70/week @ 2024-12-20 6/week @ 2024-12-27 174/week @ 2025-01-03 95/week @ 2025-01-10 40/week @ 2025-01-17 20/week @ 2025-01-24

329 downloads per month

BSD-2-Clause

19KB
194 lines

stdint

Provides C99 integer types such as uint_fast16_t, uint_least16_t etc. for interfacing with C libraries that use them in both standard and no_std environments. Inspired by Vojtech Kral's C99 crate.

The library defaults to use the std crate. You can therefore simply add the dependency to your Cargo.toml file:

[dependencies]
stdint = "*"

To use the library in no_std environment, disable the use of default features:

[dependencies]
stdint = { version = "*", default-features = false }

Note that the specific type aliases depend on your target architecture. On docs.rs, the int_fast16_t type is currently shown as aliased to an std::ffi::c_long; this is an artifact of the documentation generator:

pub type int_fast16_t = c_long;

The actual guarantees are:

#[test]
fn int16() {
    assert_eq!(size_of::<int16_t>(), 2);
    assert!(size_of::<int_least16_t>() >= 2);
    assert!(size_of::<int_fast16_t>() >= 2);

    assert_eq!(size_of::<uint16_t>(), 2);
    assert!(size_of::<uint_least16_t>() >= 2);
    assert!(size_of::<uint_fast16_t>() >= 2);
}

To execute the tests in no_std mode, run

$ cargo test --no-default-features

Types of defined sizes

N Exact size (N bits) Smallest type with at least N bits Fastest type with at least N bits
8 int8_t, uint8_t int_least8_t, uint_least8_t int_fast8_t, uint_fast8_t
16 int16_t, uint16_t int_least16_t, uint_least16_t int_fast16_t, uint_fast16_t
32 int32_t, uint32_t int_least32_t, uint_least32_t int_fast32_t, uint_fast32_t
64 int64_t, uint64_t int_least64_t, uint_least64_t int_fast64_t, uint_fast64_t

Special types

Type Purpose
intptr_t, uintptr_t Type capable of holding *void
intmax_t, uintmax_t Largest integer type available

Constants

According MIN and MAX constants defined in stdint.h are exposed through the consts module such as INT_FAST16_MIN and INT_FAST16_MAX. Due to Rust's type system, these value are identical to int_fast16_t::MIN and int_fast16_t::MAX.

No runtime deps

~0–2MB
~38K SLoC