Trait const_panic::fmt::PanicFmt

source ·
pub trait PanicFmt {
    type This: ?Sized;
    type Kind;

    const PV_COUNT: usize;
    const PROOF: IsPanicFmt<Self, Self::This, Self::Kind> = IsPanicFmt::NEW;
}
Expand description

Trait for types that can be formatted by const panics.

Implementor

Implementors are expected to also define this inherent method to format the type:

const fn to_panicvals<'a>(&'a self, f: FmtArg) -> [PanicVal<'a>; <Self as PanicFmt>::PV_COUNT]

The returned PanicVal can also be PanicVal<'static>.

Implementation examples

This trait can be implemented in these ways (in increasing order of verbosity):

  • Using the PanicFmt derive macro (requires the opt-in "derive" feature)
  • Using the impl_panicfmt macro (requires the default-enabled "non_basic" feature)
  • Using the flatten_panicvals macro (requires the default-enabled "non_basic" feature)
  • Using no macros at all

Macro-less impl

Implementing this trait for a simple enum without using macros.

use const_panic::{ArrayString, FmtArg, PanicFmt, PanicVal};

// `ArrayString` requires the "non_basic" crate feature (enabled by default),
// everything else in this example works with no enabled crate features.
assert_eq!(
    ArrayString::<99>::concat_panicvals(&[
        &Foo::Bar.to_panicvals(FmtArg::DEBUG),
        &[PanicVal::write_str(",")],
        &Foo::Baz.to_panicvals(FmtArg::DEBUG),
        &[PanicVal::write_str(",")],
        &Foo::Qux.to_panicvals(FmtArg::DEBUG),
    ]).unwrap(),
    "Bar,Baz,Qux",
);


enum Foo {
    Bar,
    Baz,
    Qux,
}

impl PanicFmt for Foo {
    type This = Self;
    type Kind = const_panic::IsCustomType;
    const PV_COUNT: usize = 1;
}

impl Foo {
    pub const fn to_panicvals(self, _: FmtArg) -> [PanicVal<'static>; Foo::PV_COUNT] {
        match self {
            Self::Bar => [PanicVal::write_str("Bar")],
            Self::Baz => [PanicVal::write_str("Baz")],
            Self::Qux => [PanicVal::write_str("Qux")],
        }
    }
}

Required Associated Types§

source

type This: ?Sized

The type after dereferencing all references.

User-defined types should generally set this to Self.

source

type Kind

Whether this is a user-defined type or standard library type.

User-defined types should generally set this to IsCustomType.

Required Associated Constants§

source

const PV_COUNT: usize

The length of the array returned in Self::to_panicvals (an inherent method that formats the type for panic messages).

Provided Associated Constants§

source

const PROOF: IsPanicFmt<Self, Self::This, Self::Kind> = IsPanicFmt::NEW

A marker type that proves that Self implements PanicFmt.

Used by const_panic macros to coerce both standard library and user-defined types into some type that has a to_panicvals method.

Implementations on Foreign Types§

source§

impl PanicFmt for RangeToInclusive<usize>

source§

impl<'s> PanicFmt for [bool]

§

type This = [bool]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for u16

§

type This = u16

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s> PanicFmt for [&'s str]

§

type This = [&'s str]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<T> PanicFmt for Option<T>where T: PanicFmt,

Note: there is only to_panicvals methods for Options of standard library types for now.

source§

impl<T: ?Sized> PanicFmt for *mut T

§

type This = *mut T

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for u64

§

type This = u64

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s> PanicFmt for [i128]

§

type This = [i128]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for NonZeroUsize

source§

impl PanicFmt for NonZeroI16

source§

impl<'s> PanicFmt for [i64]

§

type This = [i64]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for PhantomPinned

source§

impl<'s> PanicFmt for [u32]

§

type This = [u32]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s, const LEN: usize> PanicFmt for [u64; LEN]

§

type This = [u64; LEN]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for char

§

type This = char

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s> PanicFmt for [i8]

§

type This = [i8]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for i8

§

type This = i8

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<T: ?Sized> PanicFmt for *const T

source§

impl PanicFmt for NonZeroU128

source§

impl PanicFmt for i16

§

type This = i16

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s, const LEN: usize> PanicFmt for [u128; LEN]

§

type This = [u128; LEN]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for RangeFull

source§

impl PanicFmt for RangeFrom<usize>

source§

impl<'s, const LEN: usize> PanicFmt for [i64; LEN]

§

type This = [i64; LEN]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for i128

§

type This = i128

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s, const LEN: usize> PanicFmt for [u8; LEN]

§

type This = [u8; LEN]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for str

§

type This = str

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for NonZeroI128

source§

impl<T: ?Sized> PanicFmt for PhantomData<T>

§

type This = PhantomData<T>

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<T: ?Sized> PanicFmt for NonNull<T>

§

type This = NonNull<T>

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for NonZeroU64

source§

impl<'s, const LEN: usize> PanicFmt for [u16; LEN]

§

type This = [u16; LEN]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s> PanicFmt for [i32]

§

type This = [i32]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s, const LEN: usize> PanicFmt for [char; LEN]

§

type This = [char; LEN]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for NonZeroIsize

source§

impl PanicFmt for NonZeroI8

source§

impl PanicFmt for isize

§

type This = isize

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s> PanicFmt for [usize]

§

type This = [usize]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s, const LEN: usize> PanicFmt for [i128; LEN]

§

type This = [i128; LEN]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s, const LEN: usize> PanicFmt for [i32; LEN]

§

type This = [i32; LEN]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for Ordering

source§

impl<'s, const LEN: usize> PanicFmt for [usize; LEN]

§

type This = [usize; LEN]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s> PanicFmt for [u64]

§

type This = [u64]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for i64

§

type This = i64

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s> PanicFmt for [isize]

§

type This = [isize]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for RangeInclusive<usize>

source§

impl PanicFmt for RangeTo<usize>

source§

impl<'a, const N: usize> PanicFmt for [PanicVal<'a>; N]

§

type This = [PanicVal<'a>; N]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = N

source§

impl<'s, const LEN: usize> PanicFmt for [bool; LEN]

§

type This = [bool; LEN]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s> PanicFmt for [i16]

§

type This = [i16]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for NonZeroU8

source§

impl PanicFmt for u32

§

type This = u32

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for NonZeroU32

source§

impl<'s, const LEN: usize> PanicFmt for [i8; LEN]

§

type This = [i8; LEN]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for Ordering

source§

impl<'s, const LEN: usize> PanicFmt for [isize; LEN]

§

type This = [isize; LEN]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s> PanicFmt for [u128]

§

type This = [u128]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s, const LEN: usize> PanicFmt for [i16; LEN]

§

type This = [i16; LEN]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for u128

§

type This = u128

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'a> PanicFmt for [PanicVal<'a>]

§

type This = [PanicVal<'a>]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 18_446_744_073_709_551_615usize

source§

impl PanicFmt for Range<usize>

§

type This = Range<usize>

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 3usize

source§

impl<'a, T: PanicFmt + ?Sized> PanicFmt for &'a T

§

type This = <T as PanicFmt>::This

§

type Kind = <T as PanicFmt>::Kind

source§

const PV_COUNT: usize = T::PV_COUNT

source§

impl PanicFmt for NonZeroI64

source§

impl<'s> PanicFmt for [u8]

§

type This = [u8]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s> PanicFmt for [char]

§

type This = [char]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s, const LEN: usize> PanicFmt for [u32; LEN]

§

type This = [u32; LEN]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for u8

§

type This = u8

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for NonZeroI32

source§

impl PanicFmt for Utf8Error

Available on crate feature rust_1_64 only.
source§

impl PanicFmt for NonZeroU16

source§

impl PanicFmt for i32

§

type This = i32

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for bool

§

type This = bool

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s> PanicFmt for [u16]

§

type This = [u16]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl<'s, const LEN: usize> PanicFmt for [&'s str; LEN]

§

type This = [&'s str; LEN]

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for usize

§

type This = usize

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for ()

§

type This = ()

§

type Kind = IsStdType

source§

const PV_COUNT: usize = 1usize

Implementors§

source§

impl PanicFmt for Delimiter

source§

impl PanicFmt for PanicVal<'_>

§

type This = PanicVal<'_>

§

type Kind = IsCustomType

source§

const PV_COUNT: usize = 1usize

source§

impl PanicFmt for Separator<'_>

§

type This = Separator<'_>

§

type Kind = IsCustomType

source§

const PV_COUNT: usize = 1usize

source§

impl<T> PanicFmt for StdWrapper<T>where T: PanicFmt,

§

type This = StdWrapper<T>

§

type Kind = IsCustomType

source§

const PV_COUNT: usize = T::PV_COUNT

source§

impl<const CAP: usize> PanicFmt for ArrayString<CAP>

§

type This = ArrayString<CAP>

§

type Kind = IsCustomType

source§

const PV_COUNT: usize = 1usize