1#![doc(html_root_url = "https://docs.rs/ntex-bytes/")]
51#![deny(clippy::pedantic)]
52#![allow(
53 unsafe_op_in_unsafe_fn,
54 clippy::must_use_candidate,
55 clippy::cast_sign_loss,
56 clippy::cast_possible_wrap,
57 clippy::cast_possible_truncation
58)]
59
60extern crate alloc;
61
62pub mod buf;
63pub use crate::buf::{Buf, BufMut};
64
65mod bvec;
66mod bytes;
67mod debug;
68mod hex;
69mod pages;
70mod serde;
71mod storage;
72mod string;
73
74pub use crate::bvec::BytesMut;
75pub use crate::bytes::Bytes;
76pub use crate::pages::{BytePage, BytePages};
77pub use crate::string::ByteString;
78
79#[doc(hidden)]
80pub use crate::storage::METADATA_SIZE;
81
82#[doc(hidden)]
83#[deprecated]
84pub type BytesVec = BytesMut;
85
86#[doc(hidden)]
87pub mod info {
88 #[derive(Copy, Clone, Debug, Eq, PartialEq)]
89 pub struct Info {
90 pub id: usize,
91 pub refs: u32,
92 pub kind: Kind,
93 pub capacity: usize,
94 }
95
96 #[derive(Copy, Clone, Debug, Eq, PartialEq)]
97 pub enum Kind {
98 Inline,
99 Static,
100 Vec,
101 }
102}
103
104#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
105pub enum BytePageSize {
106 Size4 = 0,
107 Size8 = 1,
108 #[default]
109 Size16 = 2,
110 Size24 = 3,
111 Size32 = 4,
112 Size48 = 5,
113 Size64 = 6,
114 Unset = 7,
115}
116
117impl BytePageSize {
118 const fn capacity(self) -> usize {
119 match self {
120 BytePageSize::Size4 => 4 * 1024,
121 BytePageSize::Size8 => 8 * 1024,
122 BytePageSize::Size16 => 16 * 1024,
123 BytePageSize::Size24 => 24 * 1024,
124 BytePageSize::Size32 => 32 * 1024,
125 BytePageSize::Size48 => 48 * 1024,
126 BytePageSize::Size64 | BytePageSize::Unset => 64 * 1024,
127 }
128 }
129}
130
131#[cfg(test)]
132mod tests {
133 use super::*;
134
135 #[test]
136 fn page_size() {
137 assert_eq!(BytePageSize::Size4.capacity(), 4 * 1024);
138 assert_eq!(BytePageSize::Size8.capacity(), 8 * 1024);
139 assert_eq!(BytePageSize::Size16.capacity(), 16 * 1024);
140 assert_eq!(BytePageSize::Size24.capacity(), 24 * 1024);
141 assert_eq!(BytePageSize::Size32.capacity(), 32 * 1024);
142 assert_eq!(BytePageSize::Size48.capacity(), 48 * 1024);
143 assert_eq!(BytePageSize::Size64.capacity(), 64 * 1024);
144 assert_eq!(BytePageSize::Unset.capacity(), 64 * 1024);
145 }
146}