optional ufmt::uDebug impl

This commit is contained in:
2025-07-18 21:19:30 +01:00
parent 33dda0d6ea
commit 39dcd647f2
4 changed files with 103 additions and 0 deletions

View File

@@ -1,10 +1,13 @@
use core::{convert::Infallible, fmt::Display, marker::PhantomData};
use num_traits::{float::FloatCore, PrimInt, Unsigned};
#[cfg(feature = "ufmt")]
use ufmt::derive::uDebug;
use crate::{Decimal, DecimalError};
#[derive(Debug)]
#[cfg_attr(feature = "ufmt", derive(uDebug))]
pub enum StackCalcError {
StackOverflow,
StackUnderflow,
@@ -28,6 +31,21 @@ pub struct StackCalc<F: FloatCore, const STACK: usize = 2, const DSIZE: usize =
phantom: PhantomData<F>,
}
#[cfg(feature = "ufmt")]
impl<F: FloatCore + ufmt::uDebug, const STACK: usize, const DSIZE: usize, EXP: ufmt::uDebug>
ufmt::uDebug for StackCalc<F, STACK, DSIZE, EXP>
{
fn fmt<W>(&self, f: &mut ufmt::Formatter<'_, W>) -> Result<(), W::Error>
where
W: ufmt::uWrite + ?Sized,
{
f.debug_struct("StackCalc")?
.field("stack", &self.stack.as_slice())?
.field("index", &self.index)?
.finish()
}
}
impl<F: FloatCore, const STACK: usize, const DSIZE: usize, EXP: PrimInt> Default
for StackCalc<F, STACK, DSIZE, EXP>
{