use derive_more::Display;
#[derive(Copy, Clone, Eq, PartialEq, Debug, Display)]
pub enum BytesRepresentation {
#[display("fixed size: {_0}")]
FixedSize(u64),
#[display("bounded size: {_0}")]
BoundedSize(u64),
#[display("unbounded size")]
UnboundedSize,
}
impl BytesRepresentation {
#[must_use]
pub const fn size(&self) -> Option<u64> {
match self {
Self::FixedSize(size) | Self::BoundedSize(size) => Some(*size),
Self::UnboundedSize => None,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn bytes_representation() {
let bytes_representation_fixed = BytesRepresentation::FixedSize(10);
assert_eq!(bytes_representation_fixed.size(), Some(10));
assert_eq!(
bytes_representation_fixed,
bytes_representation_fixed.clone()
);
let bytes_representation_bounded = BytesRepresentation::BoundedSize(10);
assert_eq!(bytes_representation_bounded.size(), Some(10));
assert_ne!(bytes_representation_fixed, bytes_representation_bounded);
let bytes_representation_unbounded = BytesRepresentation::UnboundedSize;
assert_eq!(bytes_representation_unbounded.size(), None);
}
}