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

Cannot implement WriteTarget for multiple word sizes #16

Open
jonas-schievink opened this issue Jun 28, 2021 · 2 comments
Open

Cannot implement WriteTarget for multiple word sizes #16

jonas-schievink opened this issue Jun 28, 2021 · 2 comments

Comments

@jonas-schievink
Copy link

I have a use case where I'd like to reuse a buffer type for multiple different DMA operations that require different word sizes and alignments. Basically what I'd like to use as the buffer type is

union Buffer {
    u8: [u8; 1024],
    i16: [i16; 512],
}

Now I'd like to implement WriteTarget twice for this type, with a u8 and i16 word. Unfortunately that doesn't work, since the word type is an associated type of the WriteTarget trait. Maybe it would be better if it was a type parameter instead?

@Sympatron
Copy link

You could add NewType wrappers around your buffer type and implement WriteTarget on those.
The trait could be changed, too, but this seems to be a rather niche use case.

@jonas-schievink
Copy link
Author

I'm not sure how I would turn a Box<Buffer> into a Box<NewtypedBuffer> though, at least when Box is some library-provided smart pointer and not alloc::boxed::Box. For example heapless' pool::singleton::Box is generic over the pool it came from, not the pointee, so I don't see a convenient way to use a newtype there.

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