Skip to main content

dope_sys/probe/
failure.rs

1use crate::probe::Check;
2
3/// Couples a canary's caller-owned identity with its exact rejection evidence.
4#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub struct Failure<P, O> {
6    probe: P,
7    check: Check<O>,
8}
9
10impl<P, O> Failure<P, O> {
11    pub const fn new(probe: P, check: Check<O>) -> Self {
12        Self { probe, check }
13    }
14
15    pub fn into_parts(self) -> (P, Check<O>) {
16        (self.probe, self.check)
17    }
18}
19
20impl<P, O: Copy> Failure<P, O> {
21    pub(super) fn unread(&self) -> Option<O> {
22        match &self.check {
23            Check::InvalidFlags(observed) => Some(*observed),
24            Check::Rejected(_) | Check::Unexpected(_) | Check::Nonterminal(_) => None,
25        }
26    }
27}