cuneiform_fields/lib.rs
1//! # Cuneiform Fields: Field level cache optimizations for Rust (no_std).
2//!
3//!
4//! This crate provides cache line size fitting optimizations to fields in structs.
5//! It is no_std and can be used in any no_std environment.
6//!
7//! This crate aligns fields with `#[repr(align(COHERENCE_LINE_SIZE))]` to decrease the time between prefetch signals for data.
8//! `COHERENCE_LINE_SIZE` can be detected or decided based on the architecture by `cuneiform` itself.
9//!
10//! ```toml
11//! [dependencies]
12//! cuneiform_fields = "0.1"
13//! ```
14//!
15//! ## Examples
16//!
17//! #### Hermetic aligned fields
18//! Align by hermetic cache line size detection mentioned in [cuneiform readme](https://github.com/vertexclique/cuneiform#----):
19//! ```rust
20//! use cuneiform_fields::prelude::*;
21//!
22//! pub struct Hermetic {
23//! data: HermeticPadding<u8>,
24//! data_2: u16,
25//! }
26//! ```
27//! In the example above `data` will be aligned by hermetic alignment but field `data_2` isn't going to be alignment optimized.
28//!
29//! #### Architecture aligned fields
30//! Align by cache line size detected by current Rust compiler architecture.
31//! If architecture isn't detected in known architectures it will fall back to default alignment:
32//! ```rust
33//! use cuneiform_fields::prelude::*;
34//!
35//! pub struct ArchSpecific {
36//! data: ArchPadding<u8>,
37//! data_2: u16,
38//! }
39//! ```
40//! In the example above `data` will be aligned by architecture alignment but field `data_2` isn't going to be alignment optimized.
41
42#![doc(
43 html_logo_url = "https://github.com/vertexclique/cuneiform-fields/raw/master/img/cuneiform-logo.png"
44)]
45// Force missing implementations
46#![warn(missing_docs)]
47#![warn(missing_debug_implementations)]
48#![no_std]
49
50pub mod alignas;
51pub mod arch;
52pub mod hermetic;
53
54pub mod prelude {
55 //!
56 //! Prelude that exports all field wrapping cache alignment types
57 pub use crate::arch::*;
58 pub use crate::hermetic::*;
59}