| 1 |
use crate::{ |
| 2 |
decompose, |
| 3 |
traits::{DynInfo, DynInfoType, Expr}, |
| 4 |
}; |
| 5 |
use core::fmt; |
| 6 |
|
| 7 |
pub struct DebugMessageImpl<'a, D: decompose::Recompose> { |
| 8 |
pub result: &'a D::Result, |
| 9 |
pub source: &'a D::Source, |
| 10 |
pub debug_lhs: &'a D::DebugLhs, |
| 11 |
pub debug_rhs: &'a D::DebugRhs, |
| 12 |
pub debug_cmp: D::DebugCmp, |
| 13 |
pub vtable: &'a D::VTable, |
| 14 |
} |
| 15 |
pub struct DebugMessage<'a, D: decompose::Recompose> { |
| 16 |
pub source: &'a WithSource<D::Source, &'static D::VTable>, |
| 17 |
pub debug_lhs: D::DebugLhs, |
| 18 |
pub debug_rhs: D::DebugRhs, |
| 19 |
pub debug_cmp: D::DebugCmp, |
| 20 |
pub message: fmt::Arguments<'a>, |
| 21 |
} |
| 22 |
impl<D: decompose::Recompose> fmt::Debug for DebugMessage<'_, D> { |
| 23 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 24 |
D::debug_final(self, f) |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
impl<D: decompose::Recompose> Copy for DebugMessage<'_, D> {} |
| 29 |
impl<D: decompose::Recompose> Clone for DebugMessage<'_, D> { |
| 30 |
fn clone(&self) -> Self { |
| 31 |
*self |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
#[derive(Copy, Clone)] |
| 36 |
pub struct WithSource<S, V> { |
| 37 |
pub source: S, |
| 38 |
pub file: &'static str, |
| 39 |
pub line: u32, |
| 40 |
pub col: u32, |
| 41 |
pub vtable: V, |
| 42 |
} |
| 43 |
|
| 44 |
#[derive(Copy, Clone)] |
| 45 |
pub struct Finalize<E> { |
| 46 |
pub inner: E, |
| 47 |
} |
| 48 |
|
| 49 |
impl<E: DynInfoType> DynInfoType for Finalize<E> { |
| 50 |
type VTable = E::VTable; |
| 51 |
const NULL_VTABLE: &'static Self::VTable = E::NULL_VTABLE; |
| 52 |
} |
| 53 |
|
| 54 |
impl<E: DynInfo> DynInfo for Finalize<E> { |
| 55 |
const VTABLE: &'static Self::VTable = E::VTABLE; |
| 56 |
} |
| 57 |
|
| 58 |
impl<E> Expr for &Finalize<E> { |
| 59 |
type Result = Result<(), ()>; |
| 60 |
type Marker = bool; |
| 61 |
|
| 62 |
#[inline(always)] |
| 63 |
fn eval_expr(&self) -> bool { |
| 64 |
core::unreachable!() |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
impl<E: Expr> Expr for &&Finalize<E> { |
| 69 |
type Result = E::Result; |
| 70 |
type Marker = E::Marker; |
| 71 |
|
| 72 |
#[inline(always)] |
| 73 |
fn eval_expr(&self) -> bool { |
| 74 |
self.inner.eval_expr() |
| 75 |
} |
| 76 |
} |