Skip to content

Latest commit

 

History

History

aligned_buffer

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

aligned_buffer

A crate for creating aligned buffers in Rust.

Usage

Add the following to your Cargo.toml:

[dependencies]
aligned_buffer = "0.1"

Import aligned_buffer::prelude::* and use the provided macro:

use aligned_buffer::prelude::*;

// This will create a buffer of 32 bytes with an alignment of 16. Additionally,
// `Buffer32` automatically implements `AlignedBuffer<32, 16>`.
#[aligned_buffer(16)]
struct Buffer32([u8; 32]);

/// This will create a buffer of 64 bytes with an alignment of 4. Additionally,
/// `Buffer64` automatically implements `AlignedBuffer<64, 4>`.
#[aligned_buffer(4)]
struct Buffer64 {
    data: [u8; 64]
}

The macro works on structs with either a single unnamed field or a single named field, with any name so long as it's a valid identifier. Additionally, it's well-behaved: any visibility modifiers or other attributes applied to the inner field or the struct itself are preserved and will be expanded.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.