Skip to content

Commit

Permalink
Release v6.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
p-avital committed Jun 26, 2024
1 parent 802267e commit 413b8fd
Show file tree
Hide file tree
Showing 19 changed files with 576 additions and 91 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 6.2.1 (api=1.1.0, abi=1.0.0)- Add support for `#[stabby::stabby(version=10, module="my::module")]` to let you change the values in those fields without having to implement the whole trait yourself.
- Add support for `serde` through the `serde` feature flag.
- Add conversions between `std` and `stabby` `String`s.
- Fix an issue where optimized layout checks would prevent compilation due to missing trait bounds.
- Fix estimation of `IStable::CType` for arrays.

# 6.1.1 (api=1.0.0, abi=1.0.0)
- Add support for multi-fields variants in `repr(C, u*)` enums.
- Deprecate support for `repr(C)` by deprecating any enum that uses it without also specifying a determinant size.
Expand Down
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ license = " EPL-2.0 OR Apache-2.0"
categories = ["development-tools::ffi", "no-std::no-alloc"]
repository = "https://github.com/ZettaScaleLabs/stabby"
readme = "stabby/README.md"
version = "6.1.1" # Track
version = "6.2.1" # Track

[workspace.dependencies]
stabby-macros = { path = "./stabby-macros/", version = "6.1.1", default-features = false } # Track
stabby-abi = { path = "./stabby-abi/", version = "6.1.1", default-features = false } # Track
stabby = { path = "./stabby/", version = "6.1.1", default-features = false } # Track
stabby-macros = { path = "./stabby-macros/", version = "6.2.1", default-features = false } # Track
stabby-abi = { path = "./stabby-abi/", version = "6.2.1", default-features = false } # Track
stabby = { path = "./stabby/", version = "6.2.1", default-features = false } # Track

abi_stable = "0.11.2"
criterion = "0.5.1"
Expand All @@ -51,5 +51,6 @@ quote = "1.0"
rand = "0.8.5"
rustversion = "1.0"
sha2-const-stable = "0.1.0"
serde = "1.0.203"
smol = "2.0.0"
syn = "1.0"
2 changes: 2 additions & 0 deletions stabby-abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ default = ["std"]
std = ["libc"]
libc = ["dep:libc"]
test = []
serde = ["dep:serde"]

abi_stable = ["dep:abi_stable"]
abi_stable-channels = ["abi_stable", "abi_stable/channels"]
Expand All @@ -44,6 +45,7 @@ stabby-macros.workspace = true
abi_stable = { workspace = true, optional = true }
libc = { workspace = true, optional = true }
rustversion = { workspace = true }
serde = { workspace = true, optional = true }
sha2-const-stable = { workspace = true }

[dev-dependencies]
Expand Down
53 changes: 53 additions & 0 deletions stabby-abi/src/alloc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,18 @@ impl<T, Alloc: IAlloc> BoxedSlice<T, Alloc> {
(slice, capacity, alloc)
}
}
impl<T, Alloc: IAlloc> core::ops::Deref for BoxedSlice<T, Alloc> {
type Target = [T];
fn deref(&self) -> &Self::Target {
self.as_slice()
}
}

impl<T, Alloc: IAlloc> core::ops::DerefMut for BoxedSlice<T, Alloc> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.as_slice_mut()
}
}
impl<T: Eq, Alloc: IAlloc> Eq for BoxedSlice<T, Alloc> {}
impl<T: PartialEq, Alloc: IAlloc> PartialEq for BoxedSlice<T, Alloc> {
fn eq(&self, other: &Self) -> bool {
Expand Down Expand Up @@ -421,3 +433,44 @@ impl<T, Alloc: IAlloc> IntoIterator for BoxedSlice<T, Alloc> {
}
}
pub use super::string::BoxedStr;

#[cfg(feature = "serde")]
mod serde_impl {
use super::*;
use crate::alloc::IAlloc;
use serde::{Deserialize, Serialize};
impl<'a, T: Serialize, Alloc: IAlloc> Serialize for BoxedSlice<T, Alloc> {

Check failure on line 442 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

this lifetime isn't used in the impl

Check failure on line 442 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 442 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

this lifetime isn't used in the impl

Check failure on line 442 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 442 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 442 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 442 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

this lifetime isn't used in the impl

Check failure on line 442 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

this lifetime isn't used in the impl
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let slice: &[T] = &*self;

Check failure on line 447 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

deref on an immutable reference

Check failure on line 447 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 447 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

deref on an immutable reference

Check failure on line 447 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 447 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 447 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 447 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

deref on an immutable reference

Check failure on line 447 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

deref on an immutable reference
slice.serialize(serializer)
}
}
impl<'a, T: Deserialize<'a>, Alloc: IAlloc + Default> Deserialize<'a> for BoxedSlice<T, Alloc> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'a>,
{
crate::alloc::vec::Vec::deserialize(deserializer).map(Into::into)
}
}
impl<'a, Alloc: IAlloc> Serialize for BoxedStr<Alloc> {

Check failure on line 459 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

this lifetime isn't used in the impl

Check failure on line 459 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 459 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

this lifetime isn't used in the impl

Check failure on line 459 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 459 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 459 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 459 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

this lifetime isn't used in the impl

Check failure on line 459 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

this lifetime isn't used in the impl
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let slice: &str = &*self;

Check failure on line 464 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

deref on an immutable reference

Check failure on line 464 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 464 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

deref on an immutable reference

Check failure on line 464 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 464 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 464 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 464 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

deref on an immutable reference

Check failure on line 464 in stabby-abi/src/alloc/boxed.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

deref on an immutable reference
slice.serialize(serializer)
}
}
impl<'a, Alloc: IAlloc + Default> Deserialize<'a> for BoxedStr<Alloc> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'a>,
{
crate::alloc::string::String::deserialize(deserializer).map(Into::into)
}
}
}
45 changes: 45 additions & 0 deletions stabby-abi/src/alloc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ impl<Alloc: IAlloc + Default> From<&str> for String<Alloc> {
}
}

impl<Alloc: IAlloc + Default> From<crate::str::Str<'_>> for String<Alloc> {
fn from(value: crate::str::Str<'_>) -> Self {
Self::default() + value.as_ref()
}
}

/// A reference counted boxed string.
#[crate::stabby]
pub struct ArcStr<Alloc: IAlloc = super::DefaultAllocator> {
Expand Down Expand Up @@ -339,3 +345,42 @@ impl core::fmt::Write for String {
self.try_concat(s).map_err(|_| core::fmt::Error)
}
}

#[cfg(feature = "std")]
mod std_impl {
use crate::alloc::IAlloc;
impl<Alloc: IAlloc + Default> From<std::string::String> for crate::alloc::string::String<Alloc> {
fn from(value: std::string::String) -> Self {
Self::from(value.as_ref())
}
}
impl<Alloc: IAlloc + Default> From<crate::alloc::string::String<Alloc>> for std::string::String {
fn from(value: crate::alloc::string::String<Alloc>) -> Self {
Self::from(value.as_ref())
}
}
}

#[cfg(feature = "serde")]
mod serde_impl {
use super::*;
use crate::alloc::IAlloc;
use serde::{Deserialize, Serialize};
impl<'a, Alloc: IAlloc> Serialize for String<Alloc> {

Check failure on line 369 in stabby-abi/src/alloc/string.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

this lifetime isn't used in the impl

Check failure on line 369 in stabby-abi/src/alloc/string.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 369 in stabby-abi/src/alloc/string.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

this lifetime isn't used in the impl

Check failure on line 369 in stabby-abi/src/alloc/string.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 369 in stabby-abi/src/alloc/string.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 369 in stabby-abi/src/alloc/string.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 369 in stabby-abi/src/alloc/string.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

this lifetime isn't used in the impl

Check failure on line 369 in stabby-abi/src/alloc/string.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

this lifetime isn't used in the impl
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let slice: &str = &*self;

Check failure on line 374 in stabby-abi/src/alloc/string.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

deref on an immutable reference

Check failure on line 374 in stabby-abi/src/alloc/string.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 374 in stabby-abi/src/alloc/string.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

deref on an immutable reference

Check failure on line 374 in stabby-abi/src/alloc/string.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 374 in stabby-abi/src/alloc/string.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 374 in stabby-abi/src/alloc/string.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 374 in stabby-abi/src/alloc/string.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

deref on an immutable reference

Check failure on line 374 in stabby-abi/src/alloc/string.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

deref on an immutable reference
slice.serialize(serializer)
}
}
impl<'a, Alloc: IAlloc + Default> Deserialize<'a> for String<Alloc> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'a>,
{
crate::str::Str::deserialize(deserializer).map(Into::into)
}
}
}
41 changes: 41 additions & 0 deletions stabby-abi/src/alloc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,3 +855,44 @@ impl<T, Alloc: IAlloc> AtomicArc<T, Alloc> {
}
}
}

#[cfg(feature = "serde")]
mod serde_impl {
use super::*;
use crate::alloc::IAlloc;
use serde::{Deserialize, Serialize};
impl<'a, T: Serialize, Alloc: IAlloc> Serialize for ArcSlice<T, Alloc> {

Check failure on line 864 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

this lifetime isn't used in the impl

Check failure on line 864 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 864 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

this lifetime isn't used in the impl

Check failure on line 864 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 864 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 864 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 864 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

this lifetime isn't used in the impl

Check failure on line 864 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

this lifetime isn't used in the impl
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let slice: &[T] = &*self;

Check failure on line 869 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

deref on an immutable reference

Check failure on line 869 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 869 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

deref on an immutable reference

Check failure on line 869 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 869 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 869 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 869 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

deref on an immutable reference

Check failure on line 869 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

deref on an immutable reference
slice.serialize(serializer)
}
}
impl<'a, T: Deserialize<'a>, Alloc: IAlloc + Default> Deserialize<'a> for ArcSlice<T, Alloc> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'a>,
{
crate::alloc::vec::Vec::deserialize(deserializer).map(Into::into)
}
}
impl<'a, Alloc: IAlloc> Serialize for ArcStr<Alloc> {

Check failure on line 881 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

this lifetime isn't used in the impl

Check failure on line 881 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 881 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

this lifetime isn't used in the impl

Check failure on line 881 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 881 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 881 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

this lifetime isn't used in the impl

Check failure on line 881 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

this lifetime isn't used in the impl

Check failure on line 881 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

this lifetime isn't used in the impl
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let slice: &str = &*self;

Check failure on line 886 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

deref on an immutable reference

Check failure on line 886 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 886 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on macOS

deref on an immutable reference

Check failure on line 886 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 886 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run 1.72 checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 886 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on ubuntu-22.04

deref on an immutable reference

Check failure on line 886 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

deref on an immutable reference

Check failure on line 886 in stabby-abi/src/alloc/sync.rs

View workflow job for this annotation

GitHub Actions / Run checks on windows-11

deref on an immutable reference
slice.serialize(serializer)
}
}
impl<'a, Alloc: IAlloc + Default> Deserialize<'a> for ArcStr<Alloc> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'a>,
{
crate::alloc::string::String::deserialize(deserializer).map(Into::into)
}
}
}
41 changes: 41 additions & 0 deletions stabby-abi/src/alloc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,3 +818,44 @@ fn test() {
}

pub use super::single_or_vec::SingleOrVec;

#[cfg(feature = "serde")]
mod serde_impl {
use super::*;
use crate::alloc::IAlloc;
use serde::{de::Visitor, Deserialize, Serialize};
impl<'a, T: Serialize, Alloc: IAlloc> Serialize for Vec<T, Alloc> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let slice: &[T] = &*self;
slice.serialize(serializer)
}
}
impl<'a, T: Deserialize<'a>, Alloc: IAlloc + Default> Deserialize<'a> for Vec<T, Alloc> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'a>,
{
deserializer.deserialize_seq(VecVisitor(core::marker::PhantomData))
}
}
pub struct VecVisitor<T, Alloc>(core::marker::PhantomData<(T, Alloc)>);
impl<'a, T: Deserialize<'a>, Alloc: IAlloc + Default> Visitor<'a> for VecVisitor<T, Alloc> {
type Value = Vec<T, Alloc>;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("A sequence")
}
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: serde::de::SeqAccess<'a>,
{
let mut this = Vec::with_capacity_in(seq.size_hint().unwrap_or(0), Alloc::default());
while let Some(v) = seq.next_element()? {
this.push(v);
}
Ok(this)
}
}
}
2 changes: 1 addition & 1 deletion stabby-abi/src/istable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ impl<O1: Unsigned, T1, O2: Unsigned, T2, R2: IBitMask> IncludesComputer<(O1, T1,
unsafe impl<A: IStable, B: IStable> IStable for Union<A, B> {
type ForbiddenValues = End;
type UnusedBits = End;
type Size = <A::Size as Unsigned>::Max<B::Size>;
type Size = <<A::Size as Unsigned>::Max<B::Size> as Unsigned>::NextMultipleOf<Self::Align>;
type Align = <A::Align as Alignment>::Max<B::Align>;
type HasExactlyOneNiche = B0;
type ContainsIndirections = <A::ContainsIndirections as Bit>::Or<B::ContainsIndirections>;
Expand Down
66 changes: 42 additions & 24 deletions stabby-abi/src/num.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
/// Returned when using [`core::convert::TryInto`] on the illegal value of a restricted integer.
#[crate::stabby]
#[derive(Clone, Copy, Default, Debug, Ord, PartialEq, PartialOrd, Eq, Hash)]
pub struct IllegalValue;
impl core::fmt::Display for IllegalValue {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Debug::fmt(&self, f)
}
}
#[cfg(feature = "std")]
impl std::error::Error for IllegalValue {}

macro_rules! define_non_max {
($NonMaxU8:ident: $u8: ty = $NonZeroU8: ty ) => {
($NonMaxU8:ident: $u8: ty = $NonZeroU8: ty; $u8s: literal ) => {
/// A number whose bit pattern is guaranteed not to be only 1s.
///
/// `x` is stored as `NonZero(!x)`, so transmuting results in wrong values.
#[repr(transparent)]
#[derive(Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on macOS

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Deserialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Serialize` in `serde`

Check failure on line 20 in stabby-abi/src/num.rs

View workflow job for this annotation

GitHub Actions / Run tests on ubuntu-22.04

failed to resolve: could not find `Deserialize` in `serde`
#[cfg_attr(feature = "serde", serde(into = $u8s))]
#[cfg_attr(feature = "serde", serde(try_from = $u8s))]
pub struct $NonMaxU8 {
inner: $NonZeroU8,
}
Expand Down Expand Up @@ -36,9 +51,9 @@ macro_rules! define_non_max {
}
}
impl TryFrom<$u8> for $NonMaxU8 {
type Error = ();
type Error = IllegalValue;
fn try_from(value: $u8) -> Result<Self, Self::Error> {
Self::new(value).ok_or(())
Self::new(value).ok_or(IllegalValue)
}
}
impl PartialOrd for $NonMaxU8 {
Expand Down Expand Up @@ -76,12 +91,15 @@ macro_rules! define_non_max {
};
}
macro_rules! define_non_x {
($NonMaxU8:ident: $u8: ty = $NonZeroU8: ty ) => {
($NonMaxU8:ident: $u8: ty = $NonZeroU8: ty; $u8s: literal ) => {
/// A number whose value is guaranteed not to be `FORBIDDEN`.
///
/// `x` is stored as `NonZero(x.wrapping_sub(FORBIDDEN))`, so transmuting results in wrong values.
#[repr(transparent)]
#[derive(Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(into = $u8s))]
#[cfg_attr(feature = "serde", serde(try_from = $u8s))]
pub struct $NonMaxU8<const FORBIDDEN: $u8> {
inner: $NonZeroU8,
}
Expand Down Expand Up @@ -113,9 +131,9 @@ macro_rules! define_non_x {
}
}
impl<const FORBIDDEN: $u8> TryFrom<$u8> for $NonMaxU8<{ FORBIDDEN }> {
type Error = ();
type Error = IllegalValue;
fn try_from(value: $u8) -> Result<Self, Self::Error> {
Self::new(value).ok_or(())
Self::new(value).ok_or(IllegalValue)
}
}
impl<const FORBIDDEN: $u8> PartialOrd for $NonMaxU8<{ FORBIDDEN }> {
Expand Down Expand Up @@ -153,25 +171,25 @@ macro_rules! define_non_x {
};
}

define_non_max!(NonMaxU8: u8 = core::num::NonZeroU8);
define_non_max!(NonMaxU16: u16 = core::num::NonZeroU16);
define_non_max!(NonMaxU32: u32 = core::num::NonZeroU32);
define_non_max!(NonMaxU64: u64 = core::num::NonZeroU64);
define_non_max!(NonMaxU128: u128 = core::num::NonZeroU128);
define_non_max!(NonMaxUsize: usize = core::num::NonZeroUsize);
define_non_max!(NonMaxU8: u8 = core::num::NonZeroU8; "u8");
define_non_max!(NonMaxU16: u16 = core::num::NonZeroU16; "u16");
define_non_max!(NonMaxU32: u32 = core::num::NonZeroU32; "u32");
define_non_max!(NonMaxU64: u64 = core::num::NonZeroU64; "u64");
define_non_max!(NonMaxU128: u128 = core::num::NonZeroU128; "u128");
define_non_max!(NonMaxUsize: usize = core::num::NonZeroUsize; "usize");

define_non_x!(NonXU8: u8 = core::num::NonZeroU8);
define_non_x!(NonXU16: u16 = core::num::NonZeroU16);
define_non_x!(NonXU32: u32 = core::num::NonZeroU32);
define_non_x!(NonXU64: u64 = core::num::NonZeroU64);
define_non_x!(NonXU128: u128 = core::num::NonZeroU128);
define_non_x!(NonXUsize: usize = core::num::NonZeroUsize);
define_non_x!(NonXI8: i8 = core::num::NonZeroI8);
define_non_x!(NonXI16: i16 = core::num::NonZeroI16);
define_non_x!(NonXI32: i32 = core::num::NonZeroI32);
define_non_x!(NonXI64: i64 = core::num::NonZeroI64);
define_non_x!(NonXI128: i128 = core::num::NonZeroI128);
define_non_x!(NonXIsize: isize = core::num::NonZeroIsize);
define_non_x!(NonXU8: u8 = core::num::NonZeroU8; "u8");
define_non_x!(NonXU16: u16 = core::num::NonZeroU16; "u16");
define_non_x!(NonXU32: u32 = core::num::NonZeroU32; "u32");
define_non_x!(NonXU64: u64 = core::num::NonZeroU64; "u64");
define_non_x!(NonXU128: u128 = core::num::NonZeroU128; "u128");
define_non_x!(NonXUsize: usize = core::num::NonZeroUsize; "usize");
define_non_x!(NonXI8: i8 = core::num::NonZeroI8; "i8");
define_non_x!(NonXI16: i16 = core::num::NonZeroI16; "i16");
define_non_x!(NonXI32: i32 = core::num::NonZeroI32; "i32");
define_non_x!(NonXI64: i64 = core::num::NonZeroI64; "i64");
define_non_x!(NonXI128: i128 = core::num::NonZeroI128; "i128");
define_non_x!(NonXIsize: isize = core::num::NonZeroIsize; "isize");

macro_rules! makeutest {
($u8: ident, $NonMaxU8: ident, $NonXU8: ident) => {
Expand Down
Loading

0 comments on commit 413b8fd

Please sign in to comment.