#coverage #macro #requirements #trace #logs #req #create

no-std mantra-rust-macros

Provides macros to create requirement traces and coverage logs for the mantra framework

4 releases (breaking)

new 0.5.0 Jun 14, 2024
0.4.0 Jun 13, 2024
0.3.0 May 28, 2024
0.1.0 Apr 29, 2024

#162 in Procedural macros

Download history 145/week @ 2024-04-29 11/week @ 2024-05-20 141/week @ 2024-05-27 7/week @ 2024-06-03

159 downloads per month
Used in 3 crates

MIT license

130 lines


This crate provides procedural macros to trace requirements using mantra. It also offers features to get requirement coverage via logs.


Requirement traces may be created using either the attribute macro req, or the function-like macro reqcov. See mantra-lang-tracing on how to specify requirement IDs using req or reqcov.

The attribute macro may be set anywhere attribute macros are allowed. At the moment, coverage logs are only generated if the macro is set on a function.


use mantra_rust_macros::{req, reqcov};

/// Coverage log is generated
fn some_fn() {
    // coverage log is generated

const SOME_CONST: usize = 1;

type SomeType = bool;

struct SomeStruct {
    /// Attribute macros cannot be set for fields.
    some_field: bool,

mod some_mod {}

trait SomeTrait {
    type A;

    /// Coverage log is generated
    fn some_trait_fn() {}

Coverage log

  • Feature log

    Enabling this feature will create coverage TRACE logs using the log crate.

  • Feature stdout

    Enabling this feature will print coverage logs to stdout.

  • Feature defmt

    Enabling this feature will print coverage logs using the defmt crate. This is intended for embedded devices.


fn some_fn() {}

The generated coverage log for the code above has the form:

mantra: req-id=`fn_trace`; file='<resolved by file!()>'; line='<resolved by line!()>';

Trace extraction

The extract feature may be enabled to extract coverage data from logs. With the feature enabled, the functions extract_first_coverage() or extract_covered_reqs() may be used.


~101K SLoC