decaf377_fmd/
clue.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::array::TryFromSliceError;

use crate::{error::Error, Precision};

/// A clue that allows probabilistic message detection.
#[derive(Debug, Clone)]
pub struct Clue(pub(crate) [u8; 68]);

impl Clue {
    /// The bits of precision for this `Clue`, if valid.
    pub fn precision(&self) -> Result<Precision, Error> {
        self.0[64].try_into()
    }
}

impl From<Clue> for Vec<u8> {
    fn from(value: Clue) -> Self {
        value.0.into()
    }
}

impl TryFrom<&[u8]> for Clue {
    type Error = TryFromSliceError;

    fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
        Ok(Self(value.try_into()?))
    }
}