rustolio_utils/bytes/mod.rs
1//
2// SPDX-License-Identifier: MPL-2.0
3//
4// Copyright (c) 2026 Tobias Binnewies. All rights reserved.
5//
6// This Source Code Form is subject to the terms of the Mozilla Public
7// License, v. 2.0. If a copy of the MPL was not distributed with this
8// file, You can obtain one at http://mozilla.org/MPL/2.0/.
9//
10
11mod generic_bytes;
12mod utf8;
13
14pub mod compression;
15pub mod encoding;
16pub mod hex;
17
18pub use bytes::{Buf, BufMut, Bytes, BytesMut};
19
20pub use generic_bytes::*;
21pub use utf8::*;
22
23// #[derive(Debug, Clone, PartialEq, Eq)]
24// pub struct Bytes(bytes::Bytes);
25
26// impl Bytes {
27// pub const fn new() -> Self {
28// Self(bytes::Bytes::new())
29// }
30
31// pub fn copy_from_slice(data: &[u8]) -> Self {
32// Self(bytes::Bytes::copy_from_slice(data))
33// }
34// }
35
36// impl Buf for Bytes {
37// #[inline]
38// fn remaining(&self) -> usize {
39// self.0.remaining()
40// }
41
42// #[inline]
43// fn chunk(&self) -> &[u8] {
44// self.0.chunk()
45// }
46
47// #[inline]
48// fn advance(&mut self, cnt: usize) {
49// self.0.advance(cnt)
50// }
51// }
52
53// impl From<bytes::Bytes> for Bytes {
54// fn from(value: bytes::Bytes) -> Self {
55// Self(value)
56// }
57// }
58
59// impl From<Vec<u8>> for Bytes {
60// fn from(value: Vec<u8>) -> Self {
61// Self(bytes::Bytes::from_owner(value))
62// }
63// }
64
65// impl From<String> for Bytes {
66// fn from(value: String) -> Self {
67// Self(bytes::Bytes::from_owner(value))
68// }
69// }
70
71// impl From<Box<[u8]>> for Bytes {
72// fn from(value: Box<[u8]>) -> Self {
73// Self(bytes::Bytes::from_owner(value))
74// }
75// }
76
77// impl From<&'static [u8]> for Bytes {
78// fn from(value: &'static [u8]) -> Self {
79// Self(bytes::Bytes::from_static(value))
80// }
81// }
82
83// impl From<&'static str> for Bytes {
84// fn from(value: &'static str) -> Self {
85// Self(bytes::Bytes::from_static(value.as_bytes()))
86// }
87// }
88
89// impl<const N: usize> From<[u8; N]> for Bytes {
90// fn from(value: [u8; N]) -> Self {
91// Self(bytes::Bytes::from_owner(value))
92// }
93// }
94
95// impl std::ops::Deref for Bytes {
96// type Target = bytes::Bytes;
97// fn deref(&self) -> &Self::Target {
98// &self.0
99// }
100// }
101
102// impl AsRef<[u8]> for Bytes {
103// fn as_ref(&self) -> &[u8] {
104// &self
105// }
106// }
107
108// impl bincode::Encode for Bytes {
109// fn encode<E: bincode::enc::Encoder>(
110// &self,
111// encoder: &mut E,
112// ) -> Result<(), bincode::error::EncodeError> {
113// bincode::Encode::encode(AsRef::<[u8]>::as_ref(self), encoder)
114// }
115// }
116
117// impl<'de, C> bincode::BorrowDecode<'de, C> for Bytes {
118// fn borrow_decode<D: bincode::de::BorrowDecoder<'de, Context = C>>(
119// decoder: &mut D,
120// ) -> Result<Self, bincode::error::DecodeError> {
121// let vec: Vec<u8> = bincode::BorrowDecode::borrow_decode(decoder)?;
122// Ok(Self::from(vec))
123// }
124// }
125
126// impl<C> bincode::Decode<C> for Bytes {
127// fn decode<D: bincode::de::Decoder<Context = C>>(
128// decoder: &mut D,
129// ) -> Result<Self, bincode::error::DecodeError> {
130// let vec: Vec<u8> = bincode::Decode::decode(decoder)?;
131// Ok(Self::from(vec))
132// }
133// }
134
135// impl serde::Serialize for Bytes {
136// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
137// where
138// S: serde::Serializer,
139// {
140// serde::Serialize::serialize(AsRef::<[u8]>::as_ref(&self), serializer)
141// }
142// }
143
144// impl<'de> serde::Deserialize<'de> for Bytes {
145// fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
146// where
147// D: serde::Deserializer<'de>,
148// {
149// let vec: Vec<u8> = serde::Deserialize::deserialize(deserializer)?;
150// Ok(Self::from(vec))
151// }
152// }