Comments (13)
As a simple use-case, this will enable us to reinterpret structures with bool
as bytes.
from bytemuck.
When the 1.0 of this crate was being developed, no one considered the ability to view a &bool
as a &u8
very valuable, so this particular trait split was skipped on.
I think this would be a breaking change to fit in to the existing crate.
Because of the safe transmute project, any work on a 2.0 is being held off until that project is done and stabilized. However, at that time we might be able to split up the traits like this.
from bytemuck.
Would it be a breaking change though?
Relaxing requirements on functions doesn't seem to break anything.
If we add blanket impls like this
instead of the other way around then all existing implementation would still work.
The downside of blanket impls in this direction is that implementing both NoPadding
and AnyBitPattern
won't make type a Pod
automagically.
from bytemuck.
I admit I'm not a trait expert, so with careful design it might be done I suppose.
I'll point some of the trait folks I know at this topic and maybe they can weigh in.
from bytemuck.
Once again I'd really like this feature, as I want to cast bytes to other types which can have padding but accept any bit pattern.
from bytemuck.
We could have a NoPadding trait that lets you turn &A into &[u8], and just have it as a separate thing from Pod. That wouldn't be a breaking change.
from bytemuck.
And currently I need the reverse. Turning &[u8]
into A: AnyBitPattern
.
Although NoPadding
has its use cases as well.
Do you still think proposed solution above may be a breaking change?
from bytemuck.
Yeah. No one I spoke to thought that it was possible to insert and extra trait into the trait tree.
from bytemuck.
I'm curious. Did they provide a counterexample?
BTW. This change below is not even required.
trait Pod: NoPadding + AnyBitPattern {}
Pod
may stay separate. Only functions bounds should be relaxed.
Given impls for any Pod
type, generic code with T: Pod
bound should be able to call function that would require T: AnyBitPattern
or T: NoPadding
.
from bytemuck.
No one showed that it couldn't be done, but no one definitely showed it can be done with absolutely no chance of breaks.
I'd rather just have a separate trait, which is assured to not break any existing code.
from bytemuck.
Do you mean that you want separate functions as well?
from bytemuck.
Yes, we should add this as just a separate group of traits and functions. No breakage that way.
from bytemuck.
This has been done as much as will happen in version 1.
Version 2 of the crate will be largely defined by how the safe-transmute project works out, so it's hard to say precisely, but this is expected to be possible at that time.
For now I'm gonna close it.
from bytemuck.
Related Issues (20)
- Raw pointer cast functions HOT 4
- Cannot use derive macros when reexporting bytemuck from library HOT 2
- Crate makes assumptions about bool values HOT 5
- Safe `offset_of` for packed structs using `addr_of`? HOT 9
- `ASSERT_SIZE_MULTIPLE_OF` when casting `&[u8]` to `&[[u8; 16]]` HOT 1
- Crate documentation is misleading, implies `Pod` required for all functions. HOT 3
- the `FooBits` type generated by `#[derive(CheckedBitPattern)]` should implement `NoUninit` if `Self` is `NoUninit` HOT 3
- False positive derive error for `TransparentWrapper` around types like `Box` HOT 1
- Potential rustc bug related to deriving ByteEq HOT 2
- no-uninit trait with interior mutability HOT 6
- Deriving Pod for arbitrary generic types HOT 1
- Why use from_bytes when you can use pod_read_unaligned? HOT 5
- Build error on nightly-2024-02-05 HOT 1
- Bytemuck 1.14.2 does not build on stable HOT 1
- Feature request: Casting owned slices or vec, I.e. Box<[u64]> to Box<[u8]> or Vec<u64> to Vec<u8> HOT 4
- conversion from `&[u8]` to `&[T]`? HOT 4
- Allow deriving `Zeroable` for enums which are `#[repr(u32, i8, etc..)]` HOT 2
- Address safety invariants in documentation HOT 1
- No documentation for the FooBits public type generated by derive(CheckedBitPattern) HOT 1
- Casts and conversions for owned, boxed slices HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bytemuck.