unaligned/
lib.rs

1//! A `#![no_std]` crate containing types for encapsulating unaligned values.
2//! 
3//! The primary type this crate provides is [`Unaligned<T>`], which stores a value of type `T` unaligned. 
4//! Storing values unaligned can be an alternative to using `#[repr(packed)]` structs (which can only be used
5//! unsafely) or carefully-sized byte arrays. The [`Unaligned<T>`] type exposes a safe mutable API for working
6//! with unaligned values, while the companion type [`UnalignedCell<T>`] is an interior mutability type that
7//! provides a shared mutable API for working with unaligned values.
8//! 
9//! Because references are required to be aligned, it is unsafe to take a reference to a potentially unaligned value.
10//! The `Unaligned<T>` type therefore encapsulates the unaligned-ness of the value, letting code take (safe) references
11//! to `Unaligned<T>`. It also provides safe mutable APIs to set, replace, and access the value without taking an unaligned
12//! reference.
13//! 
14//! Note that, in general, a safe *shared* API is not possible for unaligned values, because in order to do anything useful
15//! with an unaligned value, the value must be moved into aligned storage - an inherently exclusive operation. The
16//! `UnalignedCell<T>` type somewhat alleviates this restriction by allowing exclusive access through a shared API
17//! using the power of interior mutability.
18//! 
19//! This crate is `#![no_std]` by default. The `std` feature can be enabled to access functionality that requires the full
20//! standard library.
21//! 
22//! [`UnalignedCell<T>`]: self::cell::UnalignedCell
23
24#![no_std]
25#![forbid(unsafe_op_in_unsafe_fn)]
26
27#[cfg(feature = "std")]
28extern crate std;
29
30pub mod unaligned;
31pub mod cell;
32
33pub use self::unaligned::Unaligned;