Crate proc_assertions

Crate proc_assertions 

Source
Expand description

[Banner]

§Overview

The proc_assertions crate provides a set of procedural macros for enforcing compile-time assertions in Rust code. These macros help ensure the correctness of your code by validating structural and behavioral properties, such as field visibility, size, alignment, and mutation rules.

§Usage

You can use this crate as either a direct dependency or an indirect dependency through [proc_assertions].

§Direct Dependency

Add the following to your project’s [Cargo.toml]:

[dependencies]
proc_assertions = "0.1.1"

Then include it in your crate root (main.rs or lib.rs):

#[macro_use]
extern crate proc_assertions;

§Indirect Dependency

Alternatively, you can add it with features:

[dependencies]
proc_assertions = { version = "0.1.1", features = ["proc"] }

This will also import all macros available in proc_assertions.

§License

This project is licensed under the MIT License.

Attribute Macros§

assert_align_size
A procedural macro attribute to assert the size and alignment of a struct.
calls
Checks if a function includes all the whitelisted method calls. This macro ensures that only the methods listed in the whitelist are called within the function. If any method call outside of the whitelist is found, a compile-time error will be generated.
consumes
A function consumes a list of instances of certain types. Allows to quickly assert function argument types where Rustc cannot access.
mutates
Checks if only whitelisted fields of an instance type are mutated by a function. This macro enforces that only the fields listed in the whitelist can be mutated by the function. If any field not in the whitelist is mutated, a compile-time error will be generated.
nomutates
Checks if a public field of an instance type is only mutated by specific whitelisted functions. This macro ensures that only the functions listed in the whitelist can mutate public fields of the instance type. If any public field is mutated by a function not in the whitelist, a compile-time error will be generated.
private_fields
A procedural macro to assert that all fields in a struct are private.