Commit Graph

388 Commits

Author SHA1 Message Date
Lokathor
678c923f52 Closes https://github.com/Lokathor/bytemuck/issues/224, the Nightly feature name changed. 2024-02-06 19:50:43 -07:00
Logan Magee
5f93477418
Fix typo in AnyBitPattern docs (#221) 2024-01-24 19:58:00 -07:00
Lokathor
1e1a22e5ea chore: Release bytemuck version 1.14.1 2024-01-24 17:32:54 -07:00
Lokathor
2ae1a14a3f changelog 2024-01-24 17:32:42 -07:00
Hrvoje Nikšić
8dc32b1e50
Explicitly document that pod_read_unaligned and try_pod_read_unaligned don't panic on unallowed reads (#220)
* Explicitly document that pod_read_unaligned and try_pod_read_unaligned don't panic on unallowed reads

Their names make that reasonably clear already, but it doesn't hurt to
be explicit. Also, when choosing between `*from_bytes(x)` and
`pod_read_unaligned(x)`, it's good to have a clearly documented
criterion.

* Cosmetic doc changes

Add a couple of missing links, add a missing "like" (consistent with
other similar sentences).

* Remove redundant link

The redundant link emits a warning in `cargo doc`.
2024-01-24 17:30:59 -07:00
Lokathor
085a5f573e Revise the crate-level docs. 2023-11-26 12:44:24 -07:00
Andri
c705218630
Added custom crate path with tests (#209)
Co-authored-by: Andri <80914617+Shuray04@users.noreply.github.com>
2023-10-19 23:02:54 -06:00
Julien Cretin
fd27a5b018
Add from_box_bytes and box_bytes_of with BoxBytes type (#211)
* Add from_box_bytes and box_bytes_of with BoxBytes type

* Apply suggestions from code review

Co-authored-by: zachs18 <8355914+zachs18@users.noreply.github.com>

* Add into_raw_parts

* Add tests

* Rename from_parts to from_raw_parts

---------

Co-authored-by: zachs18 <8355914+zachs18@users.noreply.github.com>
2023-10-19 22:50:33 -06:00
Tom Dohrmann
d10fbfc6ff
allow deriving CheckedBitPattern for enums with fields (#171)
* simplify `ToTokens` impl for `Representation`

Instead of collecting the representation and modifier into `Option`s
and determining whether a comma is needed manually, we can use the
`Puncutuated` struct which handles commas automatically.

This will also make emitting the `align` modifier in the future easier.

* emit alignment modifier

This is required for correctly implementing `CheckedBitPattern` because
we need the layout of the type and its `Bits` type to have the same
layout.

* add unit test for `#[repr]` parsing

* allow multiple alignment modifiers

According to RFC #1358, if multiple alignment modifiers are specified,
the resulting alignment is the maximum of all alignment modifiers.

* actually return the error we just created

* factor out the integer Repr's into their own type

This is a preparation step for adding support for `#[repr(C, int)]`.

* allow parsing `#[repr(C, int)]`

This can be used on enums with fields.

* derive `CheckedBitPattern` for enums with fields

The implementation mostly mirrors the desugaring described at
https://doc.rust-lang.org/reference/type-layout.html

* add comments and rename some idents

* update error message

* update docs for `CheckedBitPattern` derive

* add new nested test case, change generated type naming scheme

* fix wrong comment

* small nit

---------

Co-authored-by: Gray Olson <gray@grayolson.com>
2023-09-06 17:37:07 +02:00
Lokathor
ff0b14dae9 chore: Release bytemuck version 1.14.0 2023-09-05 15:32:43 -06:00
Lokathor
88f5c8be75 chore: Release bytemuck_derive version 1.5.0 2023-09-05 15:15:09 -06:00
Lokathor
c22cf36bec docs. 2023-09-05 15:06:36 -06:00
Lokathor
01c2a07013 derive changelog 2023-09-05 15:01:53 -06:00
Lokathor
24b65bd05b changelog. 2023-09-05 14:56:04 -06:00
Lokathor
1ba4215050 Create align_offset feature so that we can continue to work on 1.34 2023-09-05 14:08:36 -06:00
sarah
caff759066
Use align_offset to check alignment (#176)
Co-authored-by: sarah <>
2023-09-05 14:04:52 -06:00
zachs18
b38d7d0e21
Have cfgs as part of the input to impl_unsafe_marker_for_simd (#207)
... so that the macro can correctly expand with `doc(cfg(...))` attributes under `feature = "nightly_docs"`.
2023-09-05 14:01:02 -06:00
Lokathor
d9b23e3518 rename these functions before publishing them. 2023-09-05 13:54:15 -06:00
Thom Chiovoloni
d790c043a8
Add functions for writing zeroed bytes to &mut impl Zeroable and &mut [impl Zeroable] (#193)
* Add functions for writing zeroed bytes to `&mut impl Zeroable` and `&mut [impl Zeroable]`

* Support `T: !Copy` in `fill_zero`/`write_zero`

* Zero bytes in the drop guard for write_zero

* Update src/lib.rs

Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com>

---------

Co-authored-by: Lokathor <zefria@gmail.com>
Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com>
2023-09-05 13:46:04 -06:00
Valentin
3c1a0d9b35
Improve assembly of Contiguous derive (#200)
`from_integer` and `into_integer` are usually provided by the trait's
default implementation. We override this implementation because it goes
through `transmute_copy`, which can lead to inefficient assembly as seen
in https://github.com/Lokathor/bytemuck/issues/175 .
2023-09-05 13:41:44 -06:00
José Luis Cruz
f047fb6aeb
improve documentation for optional features (#203)
- new feature `nightly_docs` enables `doc_cfg` unstable feature that allows showing explicit dependencies on features.
- new cargo alias `nightly_docs` for a more convenient local documentation build `cargo +nightly nightly_docs --open`.
- annotate exported items and implementations depending on some feature with the corresponding `doc(cfg())` attribute.
- add the `nightly_docs` feature to the `[package.metadata.docs.rs]` section.
2023-09-05 13:39:41 -06:00
zachs18
58445b1250
Fix derive non-run doctests. (#204)
Doctests only run in the crate proper; doctests inside of integration tests are not run.
Move the existing doctests from derive/tests/basic.rs to derive/lib.rs, expanding them to make them
better for documentation as well.
2023-09-05 13:36:10 -06:00
Lukasz Anforowicz
db69feee1e
Use safe, public APIs where possible to remove some unsafe blocks. (#206) 2023-09-05 13:34:39 -06:00
Lokathor
763d69eb15 Merge branch 'main' of https://github.com/Lokathor/bytemuck into main 2023-09-05 13:26:13 -06:00
Lokathor
16610417be tell clippy to quiet down 2023-09-05 13:26:08 -06:00
zachs18
39b42b8fa3
Zeroable derive custom bounds (#196)
* Add space because rust-analyzer thinks it's a weird literal otherwise.

* Add custom bounds for Zeroable.

* Cleanup custom bounds code.

* Only parse explicit bounds for Zeroable.

* Qualify syn types.

* If no explicit bounds are given, apply the default bounds.

* Add perfect derive semantics to `#[zeroable(bound = "...")]`.
2023-07-26 13:50:58 -06:00
Connor Horman
3b81c85c60
Update proc-macro2 (#201) 2023-07-25 16:15:01 -06:00
Lokathor
62a7ec9b38
MIPS got demoted to tier 3 so we can't CI it anymore. 2023-07-17 10:02:53 -06:00
zachs18
1ed1aaecf9
Remove FIXME and checks about NonZero[int] layout. (#199)
The layout was documented as guaranteed in 1.70.0 https://github.com/rust-lang/rust/pull/94786/
2023-07-17 10:01:10 -06:00
zachs18
588d89082d
Relax Pod for PhantomData (#195)
As with Zeroable for PhantomData.
2023-06-15 16:43:27 -06:00
zachs18
c286994891
must_cast: fix test failures and fmt. (#194)
* cargo fmt src/must.rs

* Fix must.rs test failures.

* Under miri, use should_panic instead of compile_fail for must_cast doctests.

* Add description for workaround.
2023-06-15 09:54:23 -06:00
MaulingMonkey
8f130f2b79
must_cast (#187) 2023-06-06 15:50:39 -06:00
Daniel Henry-Mantilla
e528c1662f
Add missing ?Sized for TransparentWrapperAlloc extension trait (#185)
* Add missing `?Sized` for `TransparentWrapperAlloc` extension trait

* chore: Release bytemuck version 1.13.2
2023-06-06 15:48:41 -06:00
Charles Lew
df5262b19c
Add #[doc(hidden)] on derive generated items. (#189) 2023-05-31 08:46:00 -06:00
C. K. Young
8391afa876
Make AnyBitPattern derive work for generic structs (#101)
* Allow generic structs to use `AnyBitPattern` derive.

* Attempt to nudge the CI into retrying.
2023-03-23 18:22:56 -06:00
Lokathor
b41f4cc1af chore: Release bytemuck_derive version 1.4.1 2023-03-23 15:40:54 -06:00
Lokathor
12c9871a71 changelog 2023-03-23 15:21:33 -06:00
Christopher Serr
b97dee7f90
Switch to syn 2.0 (#183)
This upgrades the derives from `syn` 1.0 to `syn` 2.0. While the MSRV
for `syn` 2.0 is not Rust 1.56 which is higher than the MSRV of
`bytemuck`, the derives don't fall under the MSRV policy.
2023-03-21 13:52:18 -06:00
Lokathor
b19f8abfe3 chore: Release bytemuck version 1.13.1 2023-02-28 13:40:46 -07:00
Lokathor
01011f76a8 update changelog. 2023-02-28 13:40:17 -07:00
Lokathor
1b1b9a0e89
Fix 177 (#178)
* reduce required bounds.

* clippy get off my case

* spelling

* clippy lints on tests.
2023-02-28 13:29:34 -07:00
zachs18
1039388f0b
Fix soundness issue of TransparentWrapper derive macro. (#173)
Uses the compiler to check that all non-wrapped fields are actually 1-ZSTs,
and uses Zeroable to check that all non-wrapped fields are "conjurable".

Additionally, relaxes the bound of `PhantomData<T: Zeroable>: Zeroable` to all `T: ?Sized`.
2023-02-17 12:24:16 -07:00
Dirk Stolle
d1655f541b
Fix a few typos (#169) 2023-01-29 16:41:40 -07:00
Tom Dohrmann
2d1f876216
various small fixes to the derive macros (#168)
* parse `repr(usize)` and `repr(isize)`

This can be used with enums.

* emit packed repr without type suffix

Previously we emitted the packed attribute with a type suffix for the
value `packed(4u32)`. This is not allowed. Instead we should emit
`packed(4)`.

* read bits instead of creating reference

This is required for packed structs where creating a reference to
fields is not allowed. We can make a copy of the bits because the bits
are `AnyBitPattern` which implies `Copy`.

* emit generics on implied traits
2023-01-25 21:49:46 -07:00
Lokathor
49c23727fa (cargo-release) version 1.13.0 2023-01-19 23:05:43 -07:00
Lokathor
0e65f1e64d bump bytemuck_derive min version. 2023-01-19 22:58:28 -07:00
Lokathor
2bcc0ef6de chore: Release bytemuck_derive version 1.4.0 2023-01-19 17:45:46 -07:00
Lokathor
28d3aa7ba9 changelog 2023-01-19 17:44:21 -07:00
Lokathor
cb5caf7bf8 (cargo-release) version 1.12.4 2023-01-19 13:48:06 -07:00
Lokathor
a8d44503f5 changelog 2023-01-19 13:41:17 -07:00