feat: trait rework#9
Merged
Merged
Conversation
i found i had scenarios where i wanted to be able to use the ParselyRead/ParselyWrite traits but not necessarily with `BitBuf`/`BitBufMut`, so I wanted to be able to use them with different buffer types. In order to do that, I needed to move the buffer back to a generic on the ParselyWrite trait. Previously this was an issue with how I was coercing the result of expressions in attributes: I needed know generics there for it to work reasonably as a trait bound. But I found putting the buffer there should work alright: it makes sense to require we can get a type that can be written to the current buffer.
…read -> into_parsely_result
There was a problem hiding this comment.
Pull Request Overview
This PR reworks the ParselyRead and ParselyWrite traits to enable manual implementations using custom types and improves type inference by removing redundant generic placeholders. Key changes include:
- Removing the redundant "_" generic type argument from read and write invocation calls in tests.
- Updating trait definitions and implementations in both the core library and code-generation modules to include the buffer type as a generic parameter.
- Adjusting padding-handling code in the generated implementations for read and write.
Reviewed Changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/ui/pass/*.rs | Updated calls to Foo::read/Foo::write to remove the redundant generic parameter. |
| tests/expand/*.expanded.rs | Modified code generation for mapping, assertion, and alignment to reflect the new trait design. |
| impl/src/parsely_read.rs, parsely_write.rs | Updated trait definitions and implementations to include an explicit BitBuf/BitsMut generic parameter. |
| impl/src/code_gen/gen_read.rs, gen_write.rs | Adjusted code generation for read/write impls to adopt the new trait structure and padding handling. |
| impl/src/error.rs | Updated the conversion utility traits to align with the removal of the "read" suffix in method calls. |
| impl/Cargo.toml | Bumped the bits-io dependency version to support the changes. |
| Notes.md | Expanded documentation clarifying support for custom types in ParselyRead/ParselyWrite. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This tweaks the
ParselyReadandParselyWritetraits yet again in order to allow manual implementations of them using a custom type. This is useful for some types which want to be able to operate onBitsdirectly instead of some genericBitBufor if some other buffer type in general wants to be used.