pub struct ComputePvCount {
    pub field_amount: usize,
    pub summed_pv_count: usize,
    pub delimiter: TypeDelim,
}
Available on crate feature non_basic only.
Expand description

For computing the PanicFmt::PV_COUNT of a struct or enum variant, with the call method.

This assumes that you write the to_panicvals method like in the flatten_panicvals examples

Examples

These examples demonstrates how to use this type by itself, for a more complete example you can look at the flatten_panicvals examples

Struct

use const_panic::{ComputePvCount, PanicFmt};

struct Foo<'a> {
    x: u32,
    y: &'a [&'a str],
    z: Bar,
}

impl PanicFmt for Foo<'_> {
    type This = Self;
    type Kind = const_panic::IsCustomType;
     
    const PV_COUNT: usize = ComputePvCount{
        field_amount: 3,
        summed_pv_count:
            u32::PV_COUNT +
            <&[&str]>::PV_COUNT +
            <Bar>::PV_COUNT,
        delimiter: const_panic::TypeDelim::Braced,
    }.call();
}

assert_eq!(Foo::PV_COUNT, 12);

Enum

use const_panic::{ComputePvCount, PanicFmt};

enum Foo {
    Bar,
    Baz(u32, u64),
}

impl PanicFmt for Foo {
    type This = Self;
    type Kind = const_panic::IsCustomType;
     
    const PV_COUNT: usize = const_panic::utils::slice_max_usize(&[
        ComputePvCount{
            field_amount: 0,
            summed_pv_count: 0,
            delimiter: const_panic::TypeDelim::Braced,
        }.call(),
        ComputePvCount{
            field_amount: 2,
            summed_pv_count: <u32>::PV_COUNT + <u64>::PV_COUNT,
            delimiter: const_panic::TypeDelim::Tupled,
        }.call(),
    ]);
}

assert_eq!(Foo::PV_COUNT, 7);

Fields§

§field_amount: usize

The amount of fields in the struct

§summed_pv_count: usize

The summed up amount of PanicVals that all the fields produce.

Eg: for a struct with Bar and Qux fields, this would be <Bar as PanicFmt>::PV_COUNT + <Qux as PanicFmt>::PV_COUNT,

§delimiter: TypeDelim

Whether it’s a tupled or braced struct/variant.

Implementations§

Does the computation.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

A constant of the type witness

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.