Struct ComputePvCount

Source
pub struct ComputePvCount {
    pub field_amount: usize,
    pub summed_pv_count: usize,
    pub delimiter: TypeDelim,
}
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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T, U> Into<U> for T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.