Commit Graph

80 Commits

Author SHA1 Message Date
Lokathor
7fa51a420d
pod_read_unaligned and try_pod_read_unaligned (#92)
* pod_read_unaligned and try_pod_read_unaligned

* only do all-features on nightly.

* I forgot we can't use .cast on 1.34
2022-03-01 18:09:49 -07:00
Christopher Serr
6029639753
Implement Pod and Zeroable for AArch64 NEON Vectors (#80)
* Implement `Pod` and `Zeroable` for AArch64 NEON Vectors

The NEON intrinsics will be stabilized in Rust 1.59.

* Compile all-features only on nightly
2021-12-21 19:01:47 -07:00
Lokathor
c8ffbd19dd Merge branch 'main' of https://github.com/Lokathor/bytemuck into main 2021-12-15 23:16:42 -07:00
Lokathor
dd01ccae42 nightly_portable_simd 2021-12-15 23:16:38 -07:00
Alphyr
3923766b67
Impls for PhantomPinned and more PhantomData (#79) 2021-12-08 18:59:22 -07:00
Christopher Serr
944c90ca3f
Support WASM SIMD's v128 type (#73)
Due to the MSRV it is behind a feature gate.
2021-10-15 13:46:52 -06:00
Gauthier Segay
9ea604addb
minor doc patch to help users adjust their Cargo.toml for usage of the allocation module. (#76)
* just pointer to how to set the crate feature

helps the Cargo newbies to enable the feature easily while reading the documentation.

* Update allocation.rs
2021-10-15 13:45:16 -06:00
Christopher Durham
1a4c11a675
Replace unsound usage of transmute_copy (#72)
* Use transmute! to enforce safer transmute_copy use

* Test fix for #71
2021-07-22 23:12:56 -06:00
Lokathor
05d956f3b4
ptr pod impl fix. (#65)
* gate the unsound impl.

* changelog

* update cargo.toml
2021-06-13 08:40:58 -06:00
Daniel McNab
291b2d2513
Just gate the Display impl instead (#69)
The old version didn't compile (because of the extra semicolon)
2021-06-13 08:12:24 -06:00
Daniel McNab
043c18b4ba
Allow building on spir-v (#67)
* Allow building on spir-v

* Remove spurious `self`
2021-06-11 13:30:50 -06:00
Lokathor
99ecb1f6cb rename "unwrap" to "peel". 2021-06-10 14:05:15 -06:00
Connor Horman
cd8dbd64e9
Attach min_const_generics to a crate feature (#63)
* Attach min_const_generics to a crate feature

* Remove `min_const_generics` detection logic
2021-06-05 08:25:57 -06:00
Zakarum
f3e16c7051
Implement Pod and Zeroable for arrays of any size (#59)
* Implement Pod and Zeroable for arrays of any size

Only when rustc version is 1.51 or newer

* Rename cfg flag after feature name
2021-04-01 19:56:49 -06:00
Luis Wirth
30a96066fa
[Feature] extend TransparentWrapper conversion functions (#58)
* update rustfmt.toml

replace `merge_imports = true` (deprecated) with `imports_granularity = "Crate"`

* run `cargo +nightly fmt`

* rewrite docs and rename `Wrapped` to `Inner`

rewriting some docs for conciseness

rename `Wrapped` to `Inner`, because it's hard to visually differentiate between
`Wrapper` and `Wrapped`

* impl missing `TransparentWrapper::wrap_{}` fns

Implement 3 new wrapping functions on `TransparentWrapper` providing new
conversions.

- `TransparentWrapper::wrap(s: Inner) -> Self`
- `TransparentWrapper::wrap_slice(s: &[Inner]) -> &[Self]`
- `TransparentWrapper::wrap_slice_mut(s: &mut [Inner]) -> &mut [Self]`

* impl `TransparentWrapper::unwrap_{}` fns

Implement counterparts to `TransparentWrapper::wrap_{}` functions
providing reverse conversions.

- `TransparentWrapper::unwrap(self) -> Inner`
- `TransparentWrapper::unwrap_ref(&self) -> &Inner`
- `TransparentWrapper::unwrap_mut(&mut self) -> &mut Inner`
- `TransparentWrapper::unwrap_slice(s: &[Self]) -> &[Inner]`
- `TransparentWrapper::unwrap_slice_mut(s: &mut [Self]) -> &mut [Inner]`

* add `TransparentWrapper` UB test

This test is only for MIRI to check all trait functions on
`TransparentWrapper` if they cause any UB.
The output of the functions is not checked.

* small `TransparentWrapper` doc adjustments

* change fn signature on `TransparentWrapper`

Methods on `TransparentWrapper` trait are now associated functions.
They now take `Self` instead of `self` as argument)

- `TransparentWrapper::unwrap(s: Self)`
- `TransparentWrapper::unwrap_ref(s: &Self)`
- `TransparentWrapper::unwrap_mut(s: &mut Self)`
2021-03-28 23:11:13 -06:00
Lokathor
e5d5061854
adjust the code to match the claims of the docs. (#53) 2021-02-17 21:43:32 -07:00
Lokathor
7e76723b3d
pod_collect_to_vec (#50)
* add the requested feature.

* maybe we need to be more aggressive than cargo clean is?
2021-01-13 16:49:11 -07:00
Marvin Löbel
92ce415317
Prevent try_zeroed_box<T>() from reserving size_of<T>() space on the stack. (#43)
* Add test

* Change try_zeroed_box implementation to not allocate space for T on the stack

* Add second test
2020-10-21 14:11:09 -06:00
Thom Chiovoloni
64cc5973c4
Add more tests, overhaul CI, and fix plug soundness hole in bytemuck::offset_of! (#38)
* Ensure functions that take generic <A, B> don't call them <T, U>

* Plug soundness hole in offset_of with safe_packed_borrows lint

* Add some more tests I noticed were missing (still many missing)

* Make CI way more thorough

* Fix running MSRV tests with unsupported `--feature`s

* Disable derive tests in sanitizers, and fix miri ci
2020-09-06 18:56:41 -06:00
Robin Appelman
24b71e078f
add derive macro for Contiguous (#31) 2020-08-21 16:08:34 -06:00
Robin Appelman
cf944452b7
add basic derive macro for Pod, Zeroable and TransparentWrapper for structs (#30)
* add basic derive macro for Pod and Zeroable for structs

* add derive macro for TransparentWrapper

* use core::mem::size_of instead of std::mem::size_of in generated code

* cleanup error handling a bit

* remove unneeded iter logic

* remove unneeded clone and order impl

* fix generics

* fix doc typo

Co-authored-by: Lucien Greathouse <me@lpghatguy.com>

* remove unneeded lifetime anotation

* use unreachable for already rejected patch

Co-authored-by: Lucien Greathouse <me@lpghatguy.com>
2020-08-20 19:04:36 -06:00
Lokathor
4d819357ba opt-in zeroable for maybe_unint 2020-08-19 21:43:44 -06:00
Lokathor
6414f14815 Use transmute_copy where appropriate. Format some docs. 2020-08-18 17:02:06 -06:00
Lokathor
436abe3e89 convert to resize_with 2020-07-25 15:53:27 -06:00
Lokathor
a2baf0abb3 use the correct (weaker) trait bound. 2020-07-25 15:50:10 -06:00
Lokathor
a1ef436bfa test new CI 2020-07-25 15:43:31 -06:00
Soveu
52be254e2c
zeroed_slice_box returns Result (#28)
It returns `Result<(), Box>` instead of `Box`
`cargo check` catched it
How did it pass CI?
2020-07-25 15:26:28 -06:00
Lokathor
4f2a822cb6 Correct the error variant returned in some situations. 2020-07-24 20:41:57 -06:00
Lokathor
51f1121d4f Add zeroed_slice_box 2020-07-24 20:34:32 -06:00
Lokathor
b531b050f3 Part of https://github.com/Lokathor/bytemuck/issues/21 2020-07-24 06:57:41 -06:00
Lokathor
1be7a90f16 Closes https://github.com/Lokathor/bytemuck/issues/22 2020-07-24 06:53:43 -06:00
Lokathor
3fc1e6ca4c Merge branch 'master' of https://github.com/Lokathor/bytemuck 2020-07-23 20:22:52 -06:00
Lokathor
c9a387a8da update offset_of to have 2-arg and 3-arg versions. 2020-07-23 20:21:09 -06:00
Lokathor
93e9b53571
Merge pull request #17 from HeroicKatora/master
Add a method to allocate zeroed slices
2020-07-23 19:06:59 -06:00
Andreas Molzer
11e791c88a Add a method to allocate zeroed slices
Note that the method requires a Pod and not only a Zeroable structure
since only the latter guarantees that slices have a consistent layout.
We need to compute this layout to manually allocate it.
2020-07-23 22:10:49 +02:00
Lokathor
fa686336e7 factor the panic to one spot. 2020-02-06 19:38:05 -07:00
Lokathor
cd8ed37eae Remove the unreachable_unchecked 2020-02-06 19:18:10 -07:00
Lokathor
326c78d127 formatting 2020-02-04 00:20:12 -07:00
Lokathor
c0c3b38025 eliminate some dead branches 2020-02-04 00:18:22 -07:00
Lokathor
6feac18319
Merge pull request #15 from thomcc/transparent
Add TransparentWrapper marker trait
2020-01-29 01:16:21 -07:00
Lokathor
f5d5523f77 Pod safety documentation change
The previous requirements were incorrect because I misunderstood how `repr(packed)` actually means `repr(Rust, packed)` rather than `repr(C, packed)` as I first assumed.
Closes https://github.com/Lokathor/bytemuck/issues/14
2020-01-29 01:08:14 -07:00
Thom Chiovoloni
e415a28966 Duplicate the doctests for the sake of miri 2020-01-11 08:01:58 -08:00
Thom Chiovoloni
f62e320bba Rework TransparentWrapper to not require that the wrapped type be public 2020-01-11 07:31:17 -08:00
Thom Chiovoloni
c383083c16 Add TransparentWrapper marker trait 2020-01-11 06:28:11 -08:00
Thom Chiovoloni
d9ca3306dd Add Contiguous trait 2019-12-11 19:04:23 -08:00
Thom Chiovoloni
ac3133170a Add a sound offset_of macro 2019-12-10 08:40:14 -08:00
Lokathor
93dade1ab1 documentation consistency 2019-12-06 12:31:51 -07:00
Simon Sapin
6e54fc51fb Add from_bytes, from_bytes_mut, try_from_bytes, try_from_bytes_mut
This can be useful when receiving a bytes buffer from I/O
2019-12-06 13:23:08 +01:00
Lokathor
de517daffa MaybeUninit has to wait for later. 2019-11-25 19:21:38 -07:00
Lokathor
91aeef0b45 much more docs. 2019-11-25 19:09:26 -07:00