Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-uninit trait with interior mutability #218

Open
m-mueller678 opened this issue Jan 5, 2024 · 6 comments
Open

no-uninit trait with interior mutability #218

m-mueller678 opened this issue Jan 5, 2024 · 6 comments

Comments

@m-mueller678
Copy link

I would like a marker trait that enforces only the must not contain any uninit (or padding) bytes requirement. In particular, it should allow interior mutability. While I cannot think of any safe functions bytemuck could implement just with those guarantees, it is still a nice invariant to have. I am currently implementing multiple types that need this and am manually checking that there is no padding in there. Having it automatically checked via a derive macro similar to Uninit would be much less error-prone. Bytemuck seems like a natural place to put this, as it has other memory-related marker traits and there is probably a lot of overlap in the proc-macro functionality.

@Lokathor
Copy link
Owner

Lokathor commented Jan 5, 2024

Doesn't NoUninit have a derive already?

@m-mueller678
Copy link
Author

It does, but it does not permit interior mutability. I'm looking for a more relaxed version of NoUninit

@Lokathor
Copy link
Owner

Lokathor commented Jan 5, 2024

Ah, right.

Well then as you say, I'm not sure what operation such a trait allows, since the interior mutability part makes most things probably not work quite right.

@m-mueller678
Copy link
Author

I don't think this alone allows you to implement any useful operations. It just offloads some of the work of manual checking onto the type system. I definitely want a trait like that, but making a new crate just for this one marker trait feels overkill. So I thought, bytemuck would be a good place to put it.

@Lokathor
Copy link
Owner

Lokathor commented Jan 5, 2024

If it doesn't allow at least one operation I'm unclear why you'd want to put the info in the type system though.

@m-mueller678
Copy link
Author

I use it as a bound on traits that have additional requirements which must be checked manually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants