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

Make #[derive(IntoBytes)] support more generic types #2063

Open
joshlf opened this issue Nov 15, 2024 · 1 comment
Open

Make #[derive(IntoBytes)] support more generic types #2063

joshlf opened this issue Nov 15, 2024 · 1 comment

Comments

@joshlf
Copy link
Member

joshlf commented Nov 15, 2024

Here's an idea for making #[derive(IntoBytes)] smarter on generic types: we can see from the surface syntax which fields are based on generic types and which are entirely concrete. Then, we can perform const computation based on those concrete types to extract partial information about the type. We can then use that partial information to infer bounds that must hold of generic types.

For example, if we could use const code to compute the maximum alignment that we could tolerate for a given field, then we could emit a bound of F: Unaligned<{derive_generated_computation}> for that field.

@joshlf joshlf changed the title Make #[derive(IntoBytes)] support a more generic types Make #[derive(IntoBytes)] support more generic types Nov 15, 2024
@joshlf
Copy link
Member Author

joshlf commented Feb 20, 2025

Another possible avenue that doesn't require supporting Unaligned<const ALIGN: usize>: We may be able to support fully concrete, unsized #[repr(C)] types.

In particular, we can query for the sizes of all but the last field, and we may be able to compute some layout information about the last field (although this might require KnownLayout). We could then compute whether any instance of the type would contain padding.

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

1 participant