Crates.io | just_prim_int |
lib.rs | just_prim_int |
version | 0.1.1 |
source | src |
created_at | 2022-02-09 06:39:27.037202 |
updated_at | 2022-02-14 21:00:11.509582 |
description | Primitive integer marker traits |
homepage | |
repository | https://github.com/JohnScience/just_prim_int |
max_upload_size | |
id | 529535 |
size | 10,588 |
This crate provides marker traits for primitive integers:
The unsigned integer types consist of:
Type | Minimum | Maximum |
---|
u8
| 0 | 28-1
u16
| 0 | 216-1
u32
| 0 | 232-1
u64
| 0 | 264-1
u128
| 0 | 2128-1
The signed two's complement integer types consist of:
Type | Minimum | Maximum |
---|
i8
| -(27) | 27-1
i16
| -(215) | 215-1
i32
| -(231) | 231-1
i64
| -(263) | 263-1
i128
| -(2127) | 2127-1
The usize
type is an unsigned integer type with the same number of bits as the
platform's pointer type. It can represent every memory address in the process.
The isize
type is a signed integer type with the same number of bits as the
platform's pointer type. The theoretical upper bound on object and array size
is the maximum isize
value. This ensures that isize
can be used to calculate
differences between pointers into an object or array and can address every byte
within an object along with one byte past the end.
usize
and isize
are at least 16-bits wide.
## ...
[dependencies]
just_prim_int = { version = "0.1.0" }
## ...
[features]
## https://doc.rust-lang.org/beta/unstable-book/language-features/marker-trait-attr.html
marker_trait_attr = ["just_prim_int/marker_trait_attr"]
// Uncomment if you want to conditionally use the feature. Remove otherwise.
// #![cfg_attr(feature = "marker_trait_attr", feature(marker_trait_attr))]
use just_prim_int::PrimInt;
trait MyExtensionTraitForPrimInts: PrimInt {
// ...
}
fn main() {}
cargo build <other options> --features marker_trait_attr
if you want the feature and cargo build <other options>
otherwise;cargo run<other options> --features marker_trait_attr
if you want the feature and cargo build <other options>
otherwise;cargo test <other options> --features marker_trait_attr
if you want the feature and cargo test <other options>
otherwise.With marker_trait_attr
Nightly feature, each of the provided traits also has #[marker]
attribute which allows more optimal implementation of PrimInt
via two "overlapping" generic impl
blocks, one for T: PrimSignedInt
and the other for T: PrimUnsignedInt
. Without #[marker]
attribute, they would be conflicting.
epui
- Equisized (primitive) unsigned ints for primitive ints: u8 for u8, u16 for i16, etcepsi
- Equisized (primitive) signed ints for primitive intsprimitive_promotion
- Primitive promotions for primitive numeric types: u16 for u8, i32 for i16, f64 for f32, etcis_signed_trait
- Trait for IS_SIGNED
associated constantmax_len_base_10_as_usize
- Trait offering constant maximum lengths of primitive integers as usizemin_max_traits
- Traits for MIN
and MAX
associated constantsnum_traits::int::PrimInt
- At the moment of writing, num_traits
unconditionally provides non-const trait implementations with some useful functions.