Crates.io | align_constr |
lib.rs | align_constr |
version | 0.2.0 |
source | src |
created_at | 2022-02-26 18:43:00.737136 |
updated_at | 2023-12-25 00:33:33.651844 |
description | Like `aligned` but better. Newtype whose alignment is constrained not only by the inherent alignment requirements of the underlying type but also by the alignment requirements of the "alignment constraint archetype" |
homepage | |
repository | https://github.com/JohnScience/align_constr |
max_upload_size | |
id | 540076 |
size | 23,488 |
Newtype whose alignment is constrained not only by the inherent alignment requirements of the underlying type but also by the alignment requirements of the "alignment constraint archetype". Within this context, "alignment constraint archetype" AlignConstrArchetype
is a type whose alignment constraint is imposed on the underlying type T
to produce AlignConstr<T, AlignConstrArchetype>
.
AlignConstr<T, AlignConstrArchetype>
for some underlying type T
and "alignment constraint archetype" AlignConstrArchetype
can also be seen as a refinement type reified in the form of a parameterized newtype.Not so visually appealing yet incredibly well written article that explains not only what alignment is but also why it exists and where one might need to overalign data.
Dmitrii Demenev
Rather deep exploration of the topic from the point of view of a C programming expert. The article covers not only the information about alignment but also related related topics as applied to C, as well as sever other programming languages, including Rust.
Dmitrii Demenev
use align_constr::{AlignConstr, n_zst::ZST128};
let overaligned_u8 = AlignConstr::<u8, ZST128>::new(3);
assert!(overaligned_u8.value == 3);
// requires non-const context
assert!(&overaligned_u8 as *const _ as usize % 128 == 0);
align_constr
vs aligned
aligned
is a popular library that served as a prototype for align_constr
. At the time of writing, align_constr
is featurewise and idiomatically superior and provides not only more extensive documentation but also a selection of resources on the subject. To pay respect to the contributors of aligned
crate, the quality of their creation's CI is still unmatched by align_constr
. However, the limited scope of both libraries nonetheless makes align_constr
arguably better for any use case.
Note: Unlike in aligned
, the dependency on as_slice
is optional.
align_constr
#[no_std]
friendly