paritytech / paritytech/parity-scale-codec
Custom types with `HasCompact`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 287
- Forks
- 103
- Avg merge
- 6d 13h
- Merged PRs (30d)
- 1
Description
Hi, I have a custom wrapper type that, in terms of encoding/decoding, should behave exactly as its underlying type:
type MyWrapper<T>;
I'm able to implement Encode/Decode successfully, nevertheless, if this type is used as follows:
struct Foo {
#[codec(compact)]
a: MyWrapper<u64>,
}
The compile throws an error. Basically, it requires that CompactRef<'a, MyWrapper<u64>> implements Encode/Decode. But I can not do that because both CompactRef and Encode/Decode are foreign to my crate. I can neither implement HasCompact directly because it's already implemented for T in the library, and to fulfill the conditions, I need the CompactRef implementation.
Is any way to create compactables custom types?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the HasCompact and CompactRef implementations, along with the Encode/Decode bounds used by the #[codec(compact)] attribute. Reproduce the reported failure with MyWrapper and Foo, then determine whether a supported path for custom compactable types can be provided; done means the wrapper compiles and encodes and decodes correctly under the compact attribute.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100