Skip to main content

active_reporting/
mod.rs

1//^
2//^ HEAD
3//^
4
5//> HEAD -> NO STD
6#![no_std]
7
8//> HEAD -> DOCS
9#![doc = include_str!("README.md")]
10
11//> HEAD -> LINTS
12#![allow(incomplete_features)]
13
14//> HEAD -> FEATURES
15#![feature(const_trait_impl)]
16#![feature(unsized_const_params)]
17#![feature(adt_const_params)]
18#![feature(phantom_variance_markers)]
19#![feature(negative_impls)]
20#![feature(const_heap)]
21#![feature(const_default)]
22#![feature(generic_const_exprs)]
23
24//> HEAD -> CRATES
25extern crate alloc;
26
27//> HEAD -> MODULES
28mod root;
29
30//> HEAD -> ROOT
31pub use root::Root;
32
33//> HEAD -> ALLOC
34use alloc::vec::Vec;
35
36//> HEAD -> CORE
37use core::{
38    marker::PhantomCovariantLifetime,
39    ptr::NonNull
40};
41
42
43//^ 
44//^ REPORT
45//^ 
46
47//> REPORT -> STRUCT
48pub struct Report<'valid, const NAME: &'static str> {
49    chain: NonNull<Vec<&'static str>>,
50    _lifetime: PhantomCovariantLifetime<'valid>
51}
52
53//> REPORT -> IMPLEMENTATION
54impl<'valid, const NAME: &'static str> Report<'valid, NAME> {
55    pub const fn chain(&'valid self) -> &'valid [&'static str] {
56        return unsafe {self.chain.as_ref().as_slice()};
57    }
58    pub const fn to<'next, const OTHER: &'static str>(&'valid mut self) -> Report<'next, OTHER> where 'valid: 'next {
59        if !OTHER.is_empty() {unsafe {self.chain.as_mut().push(OTHER)};}
60        return Report {
61            chain: self.chain,
62            _lifetime: PhantomCovariantLifetime::new()
63        }
64    }
65}
66
67//> REPORT -> DROP
68impl<'valid, const NAME: &'static str> Drop for Report<'valid, NAME> {
69    fn drop(&mut self) {if !NAME.is_empty() {unsafe {self.chain.as_mut().pop()};}}
70}
71
72//> REPORT -> !SEND
73impl<'valid, const NAME: &'static str> !Send for Report<'valid, NAME> {}
74
75//> REPORT -> !SYNC
76impl<'valid, const NAME: &'static str> !Sync for Report<'valid, NAME> {}