Skip to content

Commit

Permalink
Relax map_src argument bound to FnOnce (#2012)
Browse files Browse the repository at this point in the history
* Relax `map_src` argument bound to `FnOnce`

Fixes #2009

* Release v0.8.9
  • Loading branch information
jswrenn authored Nov 4, 2024
1 parent 58f0d99 commit 1fb6365
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[package]
edition = "2021"
name = "zerocopy"
version = "0.8.8"
version = "0.8.9"
authors = ["Joshua Liebow-Feeser <joshlf@google.com>"]
description = "Zerocopy makes zero-cost memory manipulation effortless. We write \"unsafe\" so you don't have to."
categories = ["embedded", "encoding", "no-std::no-alloc", "parsing", "rust-patterns"]
Expand Down Expand Up @@ -81,13 +81,13 @@ std = ["alloc"]
__internal_use_only_features_that_work_on_stable = ["alloc", "derive", "simd", "std"]

[dependencies]
zerocopy-derive = { version = "=0.8.8", path = "zerocopy-derive", optional = true }
zerocopy-derive = { version = "=0.8.9", path = "zerocopy-derive", optional = true }

# The "associated proc macro pattern" ensures that the versions of zerocopy and
# zerocopy-derive remain equal, even if the 'derive' feature isn't used.
# See: https://github.com/matklad/macro-dep-test
[target.'cfg(any())'.dependencies]
zerocopy-derive = { version = "=0.8.8", path = "zerocopy-derive" }
zerocopy-derive = { version = "=0.8.9", path = "zerocopy-derive" }

[dev-dependencies]
itertools = "0.11"
Expand All @@ -101,6 +101,6 @@ testutil = { path = "testutil" }
# CI test failures.
trybuild = { version = "=1.0.89", features = ["diff"] }
# In tests, unlike in production, zerocopy-derive is not optional
zerocopy-derive = { version = "=0.8.8", path = "zerocopy-derive" }
zerocopy-derive = { version = "=0.8.9", path = "zerocopy-derive" }
# TODO(#381) Remove this dependency once we have our own layout gadgets.
elain = "0.3.0"
12 changes: 6 additions & 6 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl<Src, Dst: ?Sized> AlignmentError<Src, Dst> {
/// });
/// ```
#[inline]
pub fn map_src<NewSrc>(self, f: impl Fn(Src) -> NewSrc) -> AlignmentError<NewSrc, Dst> {
pub fn map_src<NewSrc>(self, f: impl FnOnce(Src) -> NewSrc) -> AlignmentError<NewSrc, Dst> {
AlignmentError { src: f(self.src), dst: SendSyncPhantomData::default() }
}

Expand Down Expand Up @@ -455,7 +455,7 @@ impl<Src, Dst: ?Sized> SizeError<Src, Dst> {
/// });
/// ```
#[inline]
pub fn map_src<NewSrc>(self, f: impl Fn(Src) -> NewSrc) -> SizeError<NewSrc, Dst> {
pub fn map_src<NewSrc>(self, f: impl FnOnce(Src) -> NewSrc) -> SizeError<NewSrc, Dst> {
SizeError { src: f(self.src), dst: SendSyncPhantomData::default() }
}

Expand Down Expand Up @@ -593,7 +593,7 @@ impl<Src, Dst: ?Sized + TryFromBytes> ValidityError<Src, Dst> {
/// });
/// ```
#[inline]
pub fn map_src<NewSrc>(self, f: impl Fn(Src) -> NewSrc) -> ValidityError<NewSrc, Dst> {
pub fn map_src<NewSrc>(self, f: impl FnOnce(Src) -> NewSrc) -> ValidityError<NewSrc, Dst> {
ValidityError { src: f(self.src), dst: SendSyncPhantomData::default() }
}

Expand Down Expand Up @@ -714,7 +714,7 @@ impl<Src, Dst: ?Sized> CastError<Src, Dst> {
/// });
/// ```
#[inline]
pub fn map_src<NewSrc>(self, f: impl Fn(Src) -> NewSrc) -> CastError<NewSrc, Dst> {
pub fn map_src<NewSrc>(self, f: impl FnOnce(Src) -> NewSrc) -> CastError<NewSrc, Dst> {
match self {
Self::Alignment(e) => CastError::Alignment(e.map_src(f)),
Self::Size(e) => CastError::Size(e.map_src(f)),
Expand Down Expand Up @@ -835,7 +835,7 @@ impl<Src, Dst: ?Sized + TryFromBytes> TryCastError<Src, Dst> {
/// });
/// ```
#[inline]
pub fn map_src<NewSrc>(self, f: impl Fn(Src) -> NewSrc) -> TryCastError<NewSrc, Dst> {
pub fn map_src<NewSrc>(self, f: impl FnOnce(Src) -> NewSrc) -> TryCastError<NewSrc, Dst> {
match self {
Self::Alignment(e) => TryCastError::Alignment(e.map_src(f)),
Self::Size(e) => TryCastError::Size(e.map_src(f)),
Expand Down Expand Up @@ -900,7 +900,7 @@ impl<Src, Dst: ?Sized + TryFromBytes> TryReadError<Src, Dst> {
/// });
/// ```
#[inline]
pub fn map_src<NewSrc>(self, f: impl Fn(Src) -> NewSrc) -> TryReadError<NewSrc, Dst> {
pub fn map_src<NewSrc>(self, f: impl FnOnce(Src) -> NewSrc) -> TryReadError<NewSrc, Dst> {
match self {
Self::Alignment(i) => match i {},
Self::Size(e) => TryReadError::Size(e.map_src(f)),
Expand Down
2 changes: 1 addition & 1 deletion zerocopy-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[package]
edition = "2021"
name = "zerocopy-derive"
version = "0.8.8"
version = "0.8.9"
authors = ["Joshua Liebow-Feeser <joshlf@google.com>"]
description = "Custom derive for traits from the zerocopy crate"
license = "BSD-2-Clause OR Apache-2.0 OR MIT"
Expand Down

0 comments on commit 1fb6365

Please sign in to comment.