Skip to main content

spiritlevel/
outcome.rs

1//! What the procedures return: for bring-up, [`BringUpOutcome`] or [`BringUpError`]; for
2//! tear-down, [`TornDown`] or [`TearDownError`], with [`SinkClear`] saying what became of the
3//! sink; for the reconnect check, [`ReconnectCheck`]; for the quick restore, [`Restored`] or
4//! [`RestoreError`].
5//!
6//! `S` is the SCDC error ([`TmdsScdc::Error`](crate::TmdsScdc::Error)), `P` the PHY error.
7
8use core::fmt;
9use core::time::Duration;
10
11use hdmi_hal::ddc::{DdcError, DdcErrorKind};
12use hdmi_hal::time::Timestamp;
13
14use crate::error::UpdateError;
15use crate::event::{CancelPoint, TmdsStep};
16use crate::params::TmdsLinkParams;
17use crate::types::TmdsConfigReading;
18
19/// How a bring-up ended without an error.
20#[non_exhaustive]
21#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22pub enum BringUpOutcome<S, P> {
23    /// The link is up.
24    Up(LinkUp<S>),
25    /// The caller's cancel flag stopped the attempt. Never a failure.
26    #[non_exhaustive]
27    Cancelled {
28        /// Where the flag was seen.
29        at: CancelPoint,
30        /// The tear-down that followed, whatever `tear_down_on_error` says;
31        /// [`Cleanup::Skipped`] for a flag seen at entry, before any I/O.
32        cleanup: Cleanup<S, P>,
33        /// What went wrong before the flag was seen, without stopping the bring-up.
34        warnings: Warnings<S>,
35    },
36}
37
38/// A link that is up: steps up to the output's start completed. Whether the sink reports
39/// scrambling is the check's, part of the outcome rather than a condition of it.
40#[non_exhaustive]
41#[derive(Debug, Clone, Copy, PartialEq, Eq)]
42pub struct LinkUp<S> {
43    /// The link brought up.
44    pub link: TmdsLinkParams,
45    /// When the sink's `TMDS_Config` was written, or a write that failed was made (it may
46    /// have reached the sink); `None` when no write was due or the read of a read-modify-write
47    /// failed, so nothing was written.
48    pub sink_written_at: Option<Timestamp>,
49    /// When the output started.
50    pub output_started_at: Timestamp,
51    /// The scrambling check; [`CheckResult::NotApplicable`] on a plain link. Never
52    /// [`CheckResult::Cancelled`]: a cancelled check ends the bring-up as
53    /// [`BringUpOutcome::Cancelled`].
54    pub check: ScramblingCheck<S>,
55    /// What went wrong without stopping the bring-up.
56    pub warnings: Warnings<S>,
57}
58
59/// What went wrong without stopping a bring-up. Each kind occurs at most once per attempt.
60#[non_exhaustive]
61#[derive(Debug, Clone, Copy, PartialEq, Eq)]
62pub enum BringUpWarning<S> {
63    /// Clearing `Config_1` failed.
64    FrlRateClearFailed(S),
65    /// Clearing `FLT_update` failed, at its read or its write.
66    FltUpdateClearFailed(UpdateError<S>),
67    /// Reading `Sink_Version` failed.
68    SinkVersionReadFailed(S),
69    /// Writing `Source_Version` failed.
70    SourceVersionWriteFailed(S),
71    /// Writing the sink's `TMDS_Config` failed.
72    #[non_exhaustive]
73    TmdsConfigWriteFailed {
74        /// The error, and which half of the write failed: the read of a read-modify-write
75        /// (nothing was written) or the write (always the write for a whole-byte write).
76        error: UpdateError<S>,
77        /// On a plain link, the register read back after the failure, or the read's error;
78        /// `None` on other links, which the check covers, and when the cancel flag stopped
79        /// the bring-up before the read.
80        read_back: Option<Result<TmdsConfigReading, S>>,
81    },
82    /// Scrambled output reached the sink later after its write than the deadline allows: the
83    /// output's start, or with `Running` the scrambler coming on.
84    #[non_exhaustive]
85    DeadlineMissed {
86        /// By how much.
87        by: Duration,
88    },
89    /// The scrambling check did not see the sink report scrambled TMDS: the link is up, but
90    /// the sink may show nothing. [`LinkUp::check`] has the details.
91    #[non_exhaustive]
92    ScramblingNotConfirmed {
93        /// [`CheckResult::NotSet`] or [`CheckResult::Unreadable`].
94        result: CheckResult,
95    },
96}
97
98/// How many warnings a bring-up can gather: one of each kind.
99const WARNING_KINDS: usize = 7;
100
101/// The warnings a bring-up gathered, in the order they arose. Fixed storage, so no
102/// `alloc`, and never full: each kind occurs at most once.
103#[derive(Debug, Clone, Copy, PartialEq, Eq)]
104pub struct Warnings<S> {
105    list: [Option<BringUpWarning<S>>; WARNING_KINDS],
106    len: usize,
107}
108
109impl<S> Warnings<S> {
110    /// No warnings.
111    pub(crate) const fn new() -> Self {
112        Self {
113            list: [None, None, None, None, None, None, None],
114            len: 0,
115        }
116    }
117
118    /// Adds `warning`. A bring-up adds each kind at most once, so there is always room.
119    pub(crate) fn push(&mut self, warning: BringUpWarning<S>) {
120        if let Some(slot) = self.list.get_mut(self.len) {
121            *slot = Some(warning);
122            self.len += 1;
123        }
124    }
125
126    /// The warnings, in the order they arose.
127    pub fn iter_warnings(&self) -> impl Iterator<Item = &BringUpWarning<S>> {
128        self.list[..self.len].iter().flatten()
129    }
130
131    /// How many there are.
132    #[must_use]
133    pub const fn len(&self) -> usize {
134        self.len
135    }
136
137    /// Whether there are none.
138    #[must_use]
139    pub const fn is_empty(&self) -> bool {
140        self.len == 0
141    }
142}
143
144/// Why a bring-up stopped.
145#[non_exhaustive]
146#[derive(Debug, Clone, Copy, PartialEq, Eq)]
147pub enum BringUpError<S, P> {
148    /// The sink's `TMDS_Config` write failed with a non-transient error (`Detached`,
149    /// `Unsupported`), or at all under `OnTmdsConfigFailure::Stop`. The work before both
150    /// paths and a plain link's read-back only warn.
151    #[non_exhaustive]
152    Scdc {
153        /// The step that failed.
154        step: TmdsStep,
155        /// The error.
156        error: S,
157        /// The output's state before the cleanup.
158        output: OutputState,
159        /// What happened after the error.
160        cleanup: Cleanup<S, P>,
161        /// The warnings gathered before it.
162        warnings: Warnings<S>,
163    },
164    /// A PHY call failed.
165    #[non_exhaustive]
166    Phy {
167        /// The step that failed.
168        step: TmdsStep,
169        /// The error.
170        error: P,
171        /// The output's state before the cleanup.
172        output: OutputState,
173        /// What happened after the error.
174        cleanup: Cleanup<S, P>,
175        /// The warnings gathered before it.
176        warnings: Warnings<S>,
177    },
178    /// The video's TMDS character rate (`TmdsVideo::character_rate_khz`) is not the rate the
179    /// link was chosen for, so the PHY would be configured for one and the sink for the
180    /// other. Refused before any I/O; nothing to clean up.
181    #[non_exhaustive]
182    VideoMismatch {
183        /// The rate the link was chosen for.
184        link_rate_khz: u32,
185        /// The video's rate; `None` for a video TMDS cannot carry (a depth or format it has
186        /// no rate for).
187        video_rate_khz: Option<u32>,
188    },
189}
190
191/// What happened after a bring-up's error or cancellation.
192#[non_exhaustive]
193#[derive(Debug, Clone, Copy, PartialEq, Eq)]
194pub enum Cleanup<S, P> {
195    /// A tear-down ran (after an error with `tear_down_on_error`, the default, or after a
196    /// cancellation); its result.
197    TornDown(Result<TornDown<S>, TearDownError<S, P>>),
198    /// No tear-down: after an error with `tear_down_on_error: false`, both ends as the
199    /// error left them; or a cancellation seen at entry, before any I/O.
200    Skipped,
201}
202
203/// Whether the output may be running. Exhaustive: it is stopped or it may not be.
204#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
205pub enum OutputState {
206    /// Stopped.
207    Stopped,
208    /// May be running: started, or a call that would have started or stopped it failed.
209    MayBeRunning,
210}
211
212/// What the scrambling check found, and how.
213#[non_exhaustive]
214#[derive(Debug, Clone, Copy, PartialEq, Eq)]
215pub struct ScramblingCheck<S> {
216    /// How it ended.
217    pub result: CheckResult,
218    /// Reads made.
219    pub reads: u32,
220    /// Reads that failed.
221    pub failed_reads: u32,
222    /// The first failed read.
223    pub first_error: Option<FailedRead<S>>,
224    /// When the sink was first seen reporting scrambling, from the check's start: the
225    /// output's start, or the scrambler coming on (with `Running`, and in the quick
226    /// restore).
227    pub set_after: Option<Duration>,
228    /// The check ended on its read count, not its window: the clock did not advance as
229    /// the reads expected.
230    pub read_cap_reached: bool,
231}
232
233impl<S> ScramblingCheck<S> {
234    /// The check of a plain link: nothing read.
235    pub(crate) const NOT_APPLICABLE: Self = Self {
236        result: CheckResult::NotApplicable,
237        reads: 0,
238        failed_reads: 0,
239        first_error: None,
240        set_after: None,
241        read_cap_reached: false,
242    };
243}
244
245impl<S: DdcError> ScramblingCheck<S> {
246    /// The same record with the first error's kind in place of the error, as an event
247    /// carries it.
248    #[must_use]
249    pub fn kinds(&self) -> ScramblingCheck<DdcErrorKind> {
250        ScramblingCheck {
251            result: self.result,
252            reads: self.reads,
253            failed_reads: self.failed_reads,
254            first_error: self.first_error.as_ref().map(|f| FailedRead {
255                error: f.error.kind(),
256                after: f.after,
257            }),
258            set_after: self.set_after,
259            read_cap_reached: self.read_cap_reached,
260        }
261    }
262}
263
264/// How the scrambling check ended.
265#[non_exhaustive]
266#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
267pub enum CheckResult {
268    /// A plain link: nothing to check.
269    NotApplicable,
270    /// The sink reports scrambled TMDS.
271    Set,
272    /// The sink did not report it within the window; the link is left running.
273    NotSet,
274    /// Every read failed, or one failed with a non-transient error; the link is left
275    /// running.
276    Unreadable,
277    /// The cancel flag stopped it.
278    Cancelled,
279}
280
281/// A failed read of the check, and when it came.
282#[non_exhaustive]
283#[derive(Debug, Clone, Copy, PartialEq, Eq)]
284pub struct FailedRead<S> {
285    /// The error.
286    pub error: S,
287    /// When it came, from the check's start (see [`ScramblingCheck::set_after`]).
288    pub after: Duration,
289}
290
291/// What became of the sink's `TMDS_Config` in a tear-down.
292#[non_exhaustive]
293#[derive(Debug, Clone, Copy, PartialEq, Eq)]
294pub enum SinkClear<S> {
295    /// The settings do not clear it (`clear_sink: false`, the default).
296    NotRequested,
297    /// The link set nothing to clear: a plain link, or a sink without SCDC.
298    NothingToClear,
299    /// The caller said the sink is gone, so nothing was written.
300    SkippedSinkGone,
301    /// It was cleared.
302    Cleared,
303    /// The write failed: a warning, as tear-down went on.
304    Failed(S),
305}
306
307impl<S: DdcError> SinkClear<S> {
308    /// The same result with the error's kind in place of the error, as an event carries it.
309    #[must_use]
310    pub fn kinds(&self) -> SinkClear<DdcErrorKind> {
311        match self {
312            Self::NotRequested => SinkClear::NotRequested,
313            Self::NothingToClear => SinkClear::NothingToClear,
314            Self::SkippedSinkGone => SinkClear::SkippedSinkGone,
315            Self::Cleared => SinkClear::Cleared,
316            Self::Failed(e) => SinkClear::Failed(e.kind()),
317        }
318    }
319}
320
321/// What the reconnect check found.
322#[non_exhaustive]
323#[derive(Debug, Clone, Copy, PartialEq, Eq)]
324pub enum ReconnectCheck<S> {
325    /// The sink's `TMDS_Config` holds what the link needs.
326    Matches,
327    /// The sink lost its `TMDS_Config`: it holds `read`, not what the link needs. The way
328    /// back is the caller's: a tear-down and a bring-up, or the quick restore.
329    #[non_exhaustive]
330    Lost {
331        /// The register as read, with its byte.
332        read: TmdsConfigReading,
333    },
334    /// The read failed; nothing was decided.
335    Unreadable(S),
336    /// No `TMDS_Config` write is due on this link ([`TmdsLinkParams::sink_config`] is
337    /// `None`: a sink without SCDC, or a plain link the policy's gate leaves unwritten), so
338    /// there is nothing to check.
339    NotApplicable,
340    /// The sink's current facts differ from those the link was chosen with: nothing was
341    /// read, as the link no longer fits the sink.
342    SinkChanged,
343}
344
345impl<S: DdcError> ReconnectCheck<S> {
346    /// The same result with the error's kind in place of the error, as an event carries it.
347    #[must_use]
348    pub fn kinds(&self) -> ReconnectCheck<DdcErrorKind> {
349        match self {
350            Self::Matches => ReconnectCheck::Matches,
351            Self::Lost { read } => ReconnectCheck::Lost { read: *read },
352            Self::Unreadable(e) => ReconnectCheck::Unreadable(e.kind()),
353            Self::NotApplicable => ReconnectCheck::NotApplicable,
354            Self::SinkChanged => ReconnectCheck::SinkChanged,
355        }
356    }
357}
358
359/// A quick restore that ran to its end.
360#[non_exhaustive]
361#[derive(Debug, Clone, Copy, PartialEq, Eq)]
362pub struct Restored<S> {
363    /// When the sink's `TMDS_Config` was written, or a write that failed was made; `None`
364    /// when no write was due or the read of a read-modify-write failed.
365    pub sink_written_at: Option<Timestamp>,
366    /// The scrambling check; [`CheckResult::NotApplicable`] on a plain link, and
367    /// [`CheckResult::Cancelled`] when the cancel flag stopped it, with the link left
368    /// running.
369    pub check: ScramblingCheck<S>,
370    /// The write failed and the restore carried on
371    /// ([`OnTmdsConfigFailure::CarryOn`](crate::OnTmdsConfigFailure::CarryOn)): its error,
372    /// with the half of a read-modify-write that failed.
373    pub write_failed: Option<UpdateError<S>>,
374}
375
376/// A quick restore that stopped. Nothing is torn down: the link was running.
377#[non_exhaustive]
378#[derive(Debug, Clone, Copy, PartialEq, Eq)]
379pub enum RestoreError<S, P> {
380    /// The sink's write failed with a non-transient error, or at all under
381    /// [`OnTmdsConfigFailure::Stop`](crate::OnTmdsConfigFailure::Stop); nothing followed.
382    Scdc(UpdateError<S>),
383    /// Setting the source's scrambler failed after the sink's write; its state is unknown.
384    #[non_exhaustive]
385    Phy {
386        /// The error.
387        error: P,
388        /// When the sink's `TMDS_Config` was written, or a write that failed was made;
389        /// `None` when no write was due or the read of a read-modify-write failed.
390        sink_written_at: Option<Timestamp>,
391        /// The write's failure, when it failed and the restore carried on.
392        write_failed: Option<UpdateError<S>>,
393    },
394}
395
396/// A tear-down in which every PHY step succeeded: the output is stopped.
397#[non_exhaustive]
398#[derive(Debug, Clone, Copy, PartialEq, Eq)]
399pub struct TornDown<S> {
400    /// What became of the sink.
401    pub sink: SinkClear<S>,
402}
403
404/// A tear-down in which at least one PHY step failed. Every step was still attempted, so a
405/// failed scrambler call does not leave the output running; each field holds the first
406/// failure of its step.
407#[non_exhaustive]
408#[derive(Debug, Clone, Copy, PartialEq, Eq)]
409pub struct TearDownError<S, P> {
410    /// What became of the sink.
411    pub sink: SinkClear<S>,
412    /// `set_scrambling(false)` failed with this error.
413    pub scrambler: Option<P>,
414    /// `stop_output` failed with this error; `None`: the output is stopped.
415    pub output: Option<P>,
416}
417
418impl<S: fmt::Display, P: fmt::Debug> fmt::Display for BringUpError<S, P> {
419    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
420        match self {
421            Self::Scdc { step, error, .. } => {
422                write!(f, "bring-up stopped at {step:?}: SCDC error: {error}")
423            }
424            Self::Phy { step, error, .. } => {
425                write!(f, "bring-up stopped at {step:?}: PHY error: {error:?}")
426            }
427            Self::VideoMismatch {
428                link_rate_khz,
429                video_rate_khz: Some(video),
430            } => write!(
431                f,
432                "bring-up refused: the link is for {link_rate_khz} kHz, the video gives {video} kHz"
433            ),
434            Self::VideoMismatch { link_rate_khz, .. } => write!(
435                f,
436                "bring-up refused: the link is for {link_rate_khz} kHz, and TMDS cannot carry the video"
437            ),
438        }
439    }
440}
441
442/// The SCDC error is the source; a PHY error, which is only `Debug`, has none.
443impl<S: core::error::Error + 'static, P: fmt::Debug> core::error::Error for BringUpError<S, P> {
444    fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
445        match self {
446            Self::Scdc { error, .. } => Some(error),
447            Self::Phy { .. } | Self::VideoMismatch { .. } => None,
448        }
449    }
450}
451
452impl<S, P: fmt::Debug> fmt::Display for TearDownError<S, P> {
453    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
454        f.write_str("tear-down: ")?;
455        match (&self.scrambler, &self.output) {
456            (Some(s), Some(o)) => write!(
457                f,
458                "turning the scrambler off failed: {s:?}; stopping the output failed: {o:?}"
459            ),
460            (Some(s), None) => write!(f, "turning the scrambler off failed: {s:?}"),
461            (None, Some(o)) => write!(f, "stopping the output failed: {o:?}"),
462            (None, None) => f.write_str("a PHY step failed"),
463        }
464    }
465}
466
467/// Its failures are the PHY's, which are only `Debug`, so it has no source.
468impl<S: fmt::Debug, P: fmt::Debug> core::error::Error for TearDownError<S, P> {}
469
470impl<S: fmt::Display, P: fmt::Debug> fmt::Display for RestoreError<S, P> {
471    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
472        match self {
473            Self::Scdc(error) => write!(f, "quick restore stopped at the sink's write: {error}"),
474            Self::Phy { error, .. } => {
475                write!(f, "quick restore: setting the scrambler failed: {error:?}")
476            }
477        }
478    }
479}
480
481/// The write's error is the source; a PHY error, which is only `Debug`, has none.
482impl<S: core::error::Error + 'static, P: fmt::Debug> core::error::Error for RestoreError<S, P> {
483    fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
484        match self {
485            Self::Scdc(error) => Some(error),
486            Self::Phy { .. } => None,
487        }
488    }
489}
490
491#[cfg(test)]
492mod tests {
493    use super::*;
494
495    #[derive(Debug, Clone, Copy, PartialEq)]
496    struct Bus;
497
498    impl fmt::Display for Bus {
499        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
500            f.write_str("bus gone")
501        }
502    }
503
504    impl core::error::Error for Bus {}
505
506    #[test]
507    fn errors_print_and_chain() {
508        extern crate std;
509        use core::error::Error;
510        use std::string::ToString;
511
512        let scdc = BringUpError::<Bus, ()>::Scdc {
513            step: TmdsStep::WriteTmdsConfig,
514            error: Bus,
515            output: OutputState::Stopped,
516            cleanup: Cleanup::Skipped,
517            warnings: Warnings::new(),
518        };
519        assert_eq!(
520            scdc.to_string(),
521            "bring-up stopped at WriteTmdsConfig: SCDC error: bus gone"
522        );
523        assert_eq!(scdc.source().unwrap().to_string(), "bus gone");
524        let phy = BringUpError::<Bus, ()>::Phy {
525            step: TmdsStep::StartOutput,
526            error: (),
527            output: OutputState::MayBeRunning,
528            cleanup: Cleanup::Skipped,
529            warnings: Warnings::new(),
530        };
531        assert_eq!(
532            phy.to_string(),
533            "bring-up stopped at StartOutput: PHY error: ()"
534        );
535        assert!(phy.source().is_none());
536        let mismatch = |video_rate_khz| BringUpError::<Bus, ()>::VideoMismatch {
537            link_rate_khz: 594_000,
538            video_rate_khz,
539        };
540        assert_eq!(
541            mismatch(Some(148_500)).to_string(),
542            "bring-up refused: the link is for 594000 kHz, the video gives 148500 kHz"
543        );
544        assert_eq!(
545            mismatch(None).to_string(),
546            "bring-up refused: the link is for 594000 kHz, and TMDS cannot carry the video"
547        );
548        assert!(mismatch(None).source().is_none());
549
550        let torn = |scrambler, output| TearDownError::<Bus, ()> {
551            sink: SinkClear::NotRequested,
552            scrambler,
553            output,
554        };
555        assert_eq!(
556            torn(Some(()), Some(())).to_string(),
557            "tear-down: turning the scrambler off failed: (); stopping the output failed: ()"
558        );
559        assert_eq!(
560            torn(Some(()), None).to_string(),
561            "tear-down: turning the scrambler off failed: ()"
562        );
563        assert_eq!(
564            torn(None, Some(())).to_string(),
565            "tear-down: stopping the output failed: ()"
566        );
567        assert_eq!(torn(None, None).to_string(), "tear-down: a PHY step failed");
568        assert!(torn(None, Some(())).source().is_none());
569
570        let restore = RestoreError::<Bus, ()>::Scdc(UpdateError::Read(Bus));
571        assert_eq!(
572            restore.to_string(),
573            "quick restore stopped at the sink's write: read failed, nothing written: bus gone"
574        );
575        assert!(restore.source().is_some());
576        let restore = RestoreError::<Bus, ()>::Phy {
577            error: (),
578            sink_written_at: None,
579            write_failed: None,
580        };
581        assert_eq!(
582            restore.to_string(),
583            "quick restore: setting the scrambler failed: ()"
584        );
585        assert!(restore.source().is_none());
586    }
587
588    #[test]
589    fn warnings_keep_the_order_and_never_overflow() {
590        let mut w = Warnings::<DdcErrorKind>::new();
591        assert!(w.is_empty());
592        w.push(BringUpWarning::SourceVersionWriteFailed(DdcErrorKind::Busy));
593        w.push(BringUpWarning::DeadlineMissed {
594            by: Duration::from_millis(3),
595        });
596        assert_eq!(w.len(), 2);
597        assert!(!w.is_empty());
598        let mut it = w.iter_warnings();
599        assert_eq!(
600            it.next(),
601            Some(&BringUpWarning::SourceVersionWriteFailed(
602                DdcErrorKind::Busy
603            ))
604        );
605        assert!(matches!(
606            it.next(),
607            Some(BringUpWarning::DeadlineMissed { .. })
608        ));
609        assert_eq!(it.next(), None);
610        drop(it);
611        // An eighth push has nowhere to go and is dropped rather than panicking; a
612        // bring-up never makes one.
613        for _ in 0..6 {
614            w.push(BringUpWarning::FrlRateClearFailed(DdcErrorKind::Other));
615        }
616        assert_eq!(w.len(), WARNING_KINDS);
617    }
618
619    #[test]
620    fn a_plain_links_check_read_nothing() {
621        let check = ScramblingCheck::<DdcErrorKind>::NOT_APPLICABLE;
622        assert_eq!(check.result, CheckResult::NotApplicable);
623        assert_eq!((check.reads, check.failed_reads), (0, 0));
624        assert!(check.first_error.is_none() && check.set_after.is_none());
625        assert!(!check.read_cap_reached);
626    }
627
628    #[test]
629    fn reconnect_kinds_keep_the_result_and_drop_the_value() {
630        let read = TmdsConfigReading::new(crate::types::SinkTmdsConfig::new(false, false), 0x80);
631        assert_eq!(
632            ReconnectCheck::<DdcErrorKind>::Unreadable(DdcErrorKind::Detached).kinds(),
633            ReconnectCheck::Unreadable(DdcErrorKind::Detached)
634        );
635        for check in [
636            ReconnectCheck::<DdcErrorKind>::Matches,
637            ReconnectCheck::Lost { read },
638            ReconnectCheck::NotApplicable,
639            ReconnectCheck::SinkChanged,
640        ] {
641            assert_eq!(check.kinds(), check);
642        }
643    }
644
645    #[test]
646    fn kinds_keeps_the_result_and_drops_the_value() {
647        assert_eq!(
648            SinkClear::<DdcErrorKind>::Failed(DdcErrorKind::Busy).kinds(),
649            SinkClear::Failed(DdcErrorKind::Busy)
650        );
651        for clear in [
652            SinkClear::<DdcErrorKind>::NotRequested,
653            SinkClear::NothingToClear,
654            SinkClear::SkippedSinkGone,
655            SinkClear::Cleared,
656        ] {
657            assert_eq!(clear.kinds(), clear);
658        }
659    }
660}