reifydb_type/value/constraint/
bytes.rs1use std::fmt::{Display, Formatter};
5
6use serde::{Deserialize, Serialize};
7
8#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
10#[repr(transparent)]
11pub struct MaxBytes(u32);
12
13impl MaxBytes {
14 pub fn new(bytes: u32) -> Self {
16 Self(bytes)
17 }
18
19 pub fn value(self) -> u32 {
21 self.0
22 }
23
24 pub const MAX: Self = Self(u32::MAX);
26
27 pub const MIN: Self = Self(0);
29}
30
31impl Display for MaxBytes {
32 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
33 self.0.fmt(f)
34 }
35}
36
37impl From<MaxBytes> for u32 {
38 fn from(max_bytes: MaxBytes) -> Self {
39 max_bytes.0
40 }
41}
42
43impl From<u32> for MaxBytes {
44 fn from(value: u32) -> Self {
45 Self::new(value)
46 }
47}
48
49impl From<MaxBytes> for usize {
50 fn from(max_bytes: MaxBytes) -> Self {
51 max_bytes.0 as usize
52 }
53}
54
55impl From<usize> for MaxBytes {
56 fn from(value: usize) -> Self {
57 Self::new(value as u32)
58 }
59}