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§

source§

impl ComputePvCount

source

pub const fn call(&self) -> usize

Does the computation.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, W> HasTypeWitness<W> for Twhere W: MakeTypeWitness<Arg = T>, T: ?Sized,

source§

const WITNESS: W = W::MAKE

A constant of the type witness
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.