1#![allow(missing_debug_implementations)]
9#![doc(hidden)]
10#![unstable(feature = "generic_assert_internals", issue = "44838")]
11
12use crate::fmt::{Debug, Formatter};
13use crate::marker::PhantomData;
14
15#[unstable(feature = "generic_assert_internals", issue = "44838")]
19pub struct TryCaptureWithoutDebug;
20
21#[unstable(feature = "generic_assert_internals", issue = "44838")]
23pub trait TryCaptureGeneric<E, M> {
24    fn try_capture(&self, to: &mut Capture<E, M>);
26}
27
28impl<E> TryCaptureGeneric<E, TryCaptureWithoutDebug> for &Wrapper<&E> {
29    #[inline]
30    fn try_capture(&self, _: &mut Capture<E, TryCaptureWithoutDebug>) {}
31}
32
33impl<E> Debug for Capture<E, TryCaptureWithoutDebug> {
34    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), core::fmt::Error> {
35        f.write_str("N/A")
36    }
37}
38
39#[unstable(feature = "generic_assert_internals", issue = "44838")]
43pub struct TryCaptureWithDebug;
44
45#[unstable(feature = "generic_assert_internals", issue = "44838")]
47pub trait TryCapturePrintable<E, M> {
48    fn try_capture(&self, to: &mut Capture<E, M>);
50}
51
52impl<E> TryCapturePrintable<E, TryCaptureWithDebug> for Wrapper<&E>
53where
54    E: Printable,
55{
56    #[inline]
57    fn try_capture(&self, to: &mut Capture<E, TryCaptureWithDebug>) {
58        to.elem = Some(*self.0);
59    }
60}
61
62impl<E> Debug for Capture<E, TryCaptureWithDebug>
63where
64    E: Printable,
65{
66    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), core::fmt::Error> {
67        match self.elem {
68            None => f.write_str("N/A"),
69            Some(ref value) => Debug::fmt(value, f),
70        }
71    }
72}
73
74#[unstable(feature = "generic_assert_internals", issue = "44838")]
83pub struct Capture<E, M> {
84    pub elem: Option<E>,
89    phantom: PhantomData<M>,
90}
91
92impl<M, T> Capture<M, T> {
93    #[inline]
94    pub const fn new() -> Self {
95        Self { elem: None, phantom: PhantomData }
96    }
97}
98
99#[unstable(feature = "generic_assert_internals", issue = "44838")]
101pub struct Wrapper<T>(pub T);
102
103#[unstable(feature = "generic_assert_internals", issue = "44838")]
105pub trait Printable: Copy + Debug {}
106
107impl<T> Printable for T where T: Copy + Debug {}