https://github.com/sunsided/stdint-rs
C99 stdint types such as uint_fast8_t for performance and interoperability.
https://github.com/sunsided/stdint-rs
c99 no-std rust stdint
Last synced: 5 months ago
JSON representation
C99 stdint types such as uint_fast8_t for performance and interoperability.
- Host: GitHub
- URL: https://github.com/sunsided/stdint-rs
- Owner: sunsided
- License: bsd-2-clause
- Fork: true (vojtechkral/rust-c99)
- Created: 2022-12-20T20:27:38.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-27T14:38:10.000Z (about 3 years ago)
- Last Synced: 2024-04-26T02:03:13.921Z (almost 2 years ago)
- Topics: c99, no-std, rust, stdint
- Language: Rust
- Homepage: https://crates.io/crates/stdint
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
## 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](https://github.com/vojtechkral/rust-c99) crate.
The library defaults to use the `std` crate. You can therefore
simply add the dependency to your `Cargo.toml` file:
```toml
[dependencies]
stdint = "*"
```
To use the library in `no_std` environment, disable the use of
default features:
```toml
[dependencies]
stdint = { version = "*", default-features = false }
```
Note that the specific type aliases depend on your target architecture. On [docs.rs](https://docs.rs/stdint/0.1.0/stdint/type.int_fast16_t.html),
the `int_fast16_t` type is currently shown as aliased to an `std::ffi::c_long`; this is an artifact
of the documentation generator:
```rust
pub type int_fast16_t = c_long;
```
The actual guarantees are:
```rust
#[test]
fn int16() {
assert_eq!(size_of::(), 2);
assert!(size_of::() >= 2);
assert!(size_of::() >= 2);
assert_eq!(size_of::(), 2);
assert!(size_of::() >= 2);
assert!(size_of::() >= 2);
}
```
To execute the tests in `no_std` mode, run
```shell
$ 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`.