#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct EnvelopeMagic(pub [u8; 2]);
impl EnvelopeMagic {
pub const MSRT: Self = Self(*b"MS");
#[must_use]
pub const fn new(bytes: [u8; 2]) -> Self {
Self(bytes)
}
#[must_use]
pub const fn bytes(self) -> [u8; 2] {
self.0
}
#[must_use]
pub fn matches_prefix(self, bytes: &[u8]) -> bool {
bytes.starts_with(&self.0)
}
}
#[cfg(test)]
mod tests {
use super::EnvelopeMagic;
#[test]
fn magic_matches_prefix() {
assert!(EnvelopeMagic::MSRT.matches_prefix(b"MSRT"));
assert!(!EnvelopeMagic::MSRT.matches_prefix(b"RT"));
}
}