summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md11
-rw-r--r--bzipper/Cargo.toml4
-rw-r--r--bzipper/src/decode/mod.rs63
-rw-r--r--bzipper/src/encode/mod.rs28
-rw-r--r--bzipper/src/sized_encode/mod.rs42
-rw-r--r--bzipper_benchmarks/Cargo.toml4
-rw-r--r--bzipper_macros/Cargo.toml2
7 files changed, 122 insertions, 32 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0c2d328..a85644f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,16 @@
This is the changelog of bzipper.
See `README.md` for more information.
+## 0.10.0
+
+* Clean up code
+* Implement `Encode` and `Decode` for `Cell` and `HashSet`
+* Implement `SizedEncode` for `Cell`
+* Add missing `SizedEncode` implementations for `Cow`, `LazyCell`, and `LazyLock`
+* Unimplement `Decode` for `Cow`, `LazyCell`, and `LazyLock`
+* Add missing `Decode` implementations for `RefCell`
+* Fix feature flags for `SizedEncode` implementations of `Rc` and `Arc`
+
## 0.9.0
* Implement `Encode` and `Decode` for `LinkedList`, `HashMap`, `Cow`, `PhantomPinned`, `LazyCell`, `LazyLock`
@@ -107,6 +117,7 @@ See `README.md` for more information.
* Add *Examples* section to readme
* Implement `SizedEncode` for all previous `Encode` types
* Bump dependency versions
+* Implement `SizedEncode` for `IpAddr`, `Ipv4Addr`, `Ipv6Addr`, `Mutex`, `Box`, `RwLock`, `Rc`, `Arc`, `Wrapping`, `Saturating`, `AtomicBool`, `AtomicU8`, `AtomicU16`, `AtomicU32`, `AtomicU64`, `AtomicI8`, `AtomicI16`, `AtomicI32`, `AtomicI64`, `AtomicUsize`, `AtomicIsize`, `SocketAddrV4`, `SocketAddrV6`, `SocketAddr`, `Range`, `RangeFrom`, `RangeFull`, `RangeInclusive`, `RangeTo`, `RangeToInclusive`, `Bound`, and `RefCell`
## 0.7.0
diff --git a/bzipper/Cargo.toml b/bzipper/Cargo.toml
index 3e5f303..a263a32 100644
--- a/bzipper/Cargo.toml
+++ b/bzipper/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "bzipper"
-version = "0.9.0"
+version = "0.10.0"
edition = "2021"
rust-version = "1.83"
documentation = "https://docs.rs/bzipper/"
@@ -24,7 +24,7 @@ alloc = []
std = []
[dependencies]
-bzipper_macros = { path = "../bzipper_macros", version = "0.9.0" }
+bzipper_macros = { path = "../bzipper_macros", version = "0.10.0" }
[lints]
workspace = true
diff --git a/bzipper/src/decode/mod.rs b/bzipper/src/decode/mod.rs
index 1fbdaa2..75ccb43 100644
--- a/bzipper/src/decode/mod.rs
+++ b/bzipper/src/decode/mod.rs
@@ -25,6 +25,7 @@ mod test;
use crate::{IStream, SizedEncode};
use crate::error::{DecodeError, Utf8Error};
+use core::cell::{Cell, RefCell};
use core::convert::Infallible;
use core::hash::Hash;
use core::marker::{PhantomData, PhantomPinned};
@@ -49,9 +50,6 @@ use core::ops::{
};
#[cfg(feature = "alloc")]
-use alloc::borrow::{Cow, ToOwned};
-
-#[cfg(feature = "alloc")]
use std::boxed::Box;
#[cfg(feature = "alloc")]
@@ -70,7 +68,7 @@ use alloc::rc::Rc;
use alloc::sync::Arc;
#[cfg(feature = "std")]
-use std::collections::HashMap;
+use std::collections::{HashMap, HashSet};
#[cfg(feature = "std")]
use std::hash::BuildHasher;
@@ -179,7 +177,17 @@ impl<T: Decode> Decode for Bound<T> {
impl<T: Decode> Decode for Box<T> {
#[inline(always)]
fn decode(stream: &mut IStream) -> Result<Self, DecodeError> {
- let value = T::decode(stream)?;
+ let value = Decode::decode(stream)?;
+
+ let this = Self::new(value);
+ Ok(this)
+ }
+}
+
+impl<T: Decode> Decode for Cell<T> {
+ #[inline(always)]
+ fn decode(stream: &mut IStream) -> Result<Self, DecodeError> {
+ let value = Decode::decode(stream)?;
let this = Self::new(value);
Ok(this)
@@ -199,18 +207,6 @@ impl Decode for char {
}
}
-#[cfg(feature = "alloc")]
-#[cfg_attr(doc, doc(cfg(feature = "alloc")))]
-impl<T: ToOwned<Owned = U>, U: Decode> Decode for Cow<'_, T> {
- #[inline(always)]
- fn decode(stream: &mut IStream) -> Result<Self, DecodeError> {
- let value = U::decode(stream)?;
-
- let this = Self::Owned(value);
- Ok(this)
- }
-}
-
#[cfg(feature = "std")]
#[cfg_attr(doc, doc(cfg(feature = "std")))]
impl<K, V, S> Decode for HashMap<K, V, S>
@@ -236,6 +232,29 @@ where
}
}
+#[cfg(feature = "std")]
+#[cfg_attr(doc, doc(cfg(feature = "std")))]
+impl<T, S> Decode for HashSet<T, S>
+where
+ T: Decode + Eq + Hash,
+ S: BuildHasher + Default,
+ {
+ #[inline]
+ fn decode(stream: &mut IStream) -> Result<Self, DecodeError> {
+ let len = Decode::decode(stream)?;
+
+ let mut this = Self::with_capacity_and_hasher(len, Default::default());
+
+ for _ in 0x0..len {
+ let key = Decode::decode(stream)?;
+
+ this.insert(key);
+ }
+
+ Ok(this)
+ }
+}
+
impl Decode for Infallible {
#[expect(clippy::panic_in_result_fn)]
#[inline(always)]
@@ -407,6 +426,16 @@ impl<T: Decode> Decode for Rc<T> {
}
}
+impl<T: Decode> Decode for RefCell<T> {
+ #[inline(always)]
+ fn decode(stream: &mut IStream) -> Result<Self, DecodeError> {
+ let value = Decode::decode(stream)?;
+
+ let this = Self::new(value);
+ Ok(this)
+ }
+}
+
impl<T: Decode, E: Decode> Decode for core::result::Result<T, E> {
#[inline]
fn decode(stream: &mut IStream) -> Result<Self, DecodeError> {
diff --git a/bzipper/src/encode/mod.rs b/bzipper/src/encode/mod.rs
index 24a377d..a5c3036 100644
--- a/bzipper/src/encode/mod.rs
+++ b/bzipper/src/encode/mod.rs
@@ -25,7 +25,7 @@ mod test;
use crate::OStream;
use crate::error::EncodeError;
-use core::cell::{LazyCell, RefCell};
+use core::cell::{Cell, LazyCell, RefCell};
use core::convert::Infallible;
use core::hash::BuildHasher;
use core::hint::unreachable_unchecked;
@@ -71,7 +71,7 @@ use alloc::rc::Rc;
use alloc::sync::Arc;
#[cfg(feature = "std")]
-use std::collections::HashMap;
+use std::collections::{HashMap, HashSet};
#[cfg(feature = "std")]
use std::sync::{LazyLock, Mutex, RwLock};
@@ -219,6 +219,13 @@ impl<T: Encode> Encode for Box<T> {
}
}
+impl<T: Encode + Copy> Encode for Cell<T> {
+ #[inline(always)]
+ fn encode(&self, stream: &mut OStream) -> Result<(), EncodeError> {
+ self.get().encode(stream)
+ }
+}
+
impl Encode for char {
#[inline(always)]
fn encode(&self, stream: &mut OStream) -> Result<(), EncodeError> {
@@ -254,6 +261,23 @@ where
}
}
+#[cfg(feature = "std")]
+#[cfg_attr(doc, doc(cfg(feature = "std")))]
+impl<T, S> Encode for HashSet<T, S>
+where
+ T: Encode,
+ S: BuildHasher,
+ {
+ #[inline(always)]
+ fn encode(&self, stream: &mut OStream) -> Result<(), EncodeError> {
+ for key in self {
+ key.encode(stream)?;
+ }
+
+ Ok(())
+ }
+}
+
// Especially useful for `Result<T, Infallible>`.
// **If** that is even needed, of course.
impl Encode for Infallible {
diff --git a/bzipper/src/sized_encode/mod.rs b/bzipper/src/sized_encode/mod.rs
index bc0dc6e..378adb5 100644
--- a/bzipper/src/sized_encode/mod.rs
+++ b/bzipper/src/sized_encode/mod.rs
@@ -24,7 +24,7 @@ mod test;
use crate::Encode;
-use core::cell::RefCell;
+use core::cell::{Cell, LazyCell, RefCell};
use core::convert::Infallible;
use core::marker::PhantomData;
use core::net::{
@@ -45,15 +45,22 @@ use core::ops::{
RangeTo,
RangeToInclusive,
};
+use std::borrow::ToOwned;
+
+#[cfg(feature = "alloc")]
+use alloc::borrow::Cow;
#[cfg(feature = "alloc")]
use alloc::boxed::Box;
-#[cfg(feature = "std")]
-use std::rc::Rc;
+#[cfg(feature = "alloc")]
+use alloc::rc::Rc;
+
+#[cfg(feature = "alloc")]
+use alloc::sync::Arc;
#[cfg(feature = "std")]
-use std::sync::{Arc, Mutex, RwLock};
+use std::sync::{LazyLock, Mutex, RwLock};
/// Denotes a size-constrained, encodable type.
///
@@ -90,8 +97,8 @@ unsafe impl<T: SizedEncode, const N: usize> SizedEncode for [T; N] {
const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE * N;
}
-#[cfg(feature = "std")]
-#[cfg_attr(doc, doc(cfg(feature = "std")))]
+#[cfg(feature = "alloc")]
+#[cfg_attr(doc, doc(cfg(feature = "alloc")))]
unsafe impl<T: SizedEncode> SizedEncode for Arc<T> {
const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE;
}
@@ -110,9 +117,18 @@ unsafe impl<T: SizedEncode> SizedEncode for Box<T> {
const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE;
}
+unsafe impl<T: Copy + SizedEncode> SizedEncode for Cell<T> {
+ const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE;
+}
+
unsafe impl SizedEncode for char {
const MAX_ENCODED_SIZE: usize = u32::MAX_ENCODED_SIZE;
+}
+#[cfg(feature = "alloc")]
+#[cfg_attr(doc, doc(cfg(feature = "alloc")))]
+unsafe impl<T: SizedEncode + ToOwned> SizedEncode for Cow<'_, T> {
+ const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE;
}
unsafe impl SizedEncode for Infallible {
@@ -135,6 +151,16 @@ unsafe impl SizedEncode for isize {
const MAX_ENCODED_SIZE: usize = i16::MAX_ENCODED_SIZE;
}
+unsafe impl<T: SizedEncode> SizedEncode for LazyCell<T> {
+ const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE;
+}
+
+#[cfg(feature = "std")]
+#[cfg_attr(doc, doc(cfg(feature = "std")))]
+unsafe impl<T: SizedEncode> SizedEncode for LazyLock<T> {
+ const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE;
+}
+
#[cfg(feature = "std")]
#[cfg_attr(doc, doc(cfg(feature = "std")))]
unsafe impl<T: SizedEncode> SizedEncode for Mutex<T> {
@@ -175,8 +201,8 @@ unsafe impl<T: SizedEncode> SizedEncode for RangeToInclusive<T> {
const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE;
}
-#[cfg(feature = "std")]
-#[cfg_attr(doc, doc(cfg(feature = "std")))]
+#[cfg(feature = "alloc")]
+#[cfg_attr(doc, doc(cfg(feature = "alloc")))]
unsafe impl<T: SizedEncode> SizedEncode for Rc<T> {
const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE;
}
diff --git a/bzipper_benchmarks/Cargo.toml b/bzipper_benchmarks/Cargo.toml
index 43f4236..0c01948 100644
--- a/bzipper_benchmarks/Cargo.toml
+++ b/bzipper_benchmarks/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "bzipper_benchmarks"
-version = "0.9.0"
+version = "0.10.0"
edition = "2021"
description = "bZipper benchmarks."
@@ -10,7 +10,7 @@ homepage.workspace = true
repository.workspace = true
[dependencies]
-bzipper = { path = "../bzipper", version = "0.9.0" }
+bzipper = { path = "../bzipper", version = "0.10.0" }
bincode = "1.3.3"
ciborium = "0.2.2"
diff --git a/bzipper_macros/Cargo.toml b/bzipper_macros/Cargo.toml
index 818b510..087ab4c 100644
--- a/bzipper_macros/Cargo.toml
+++ b/bzipper_macros/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "bzipper_macros"
-version = "0.9.0"
+version = "0.10.0"
edition = "2021"
documentation = "https://docs.rs/bzipper_macros/"