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

incr: added type dispatch #62

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

explocion
Copy link

I was trying to do some meta-programming involving ux, but I found I couldn't connect const generics to ux very well and thus I created this pull request.

@bbaldino
Copy link
Collaborator

bbaldino commented Aug 8, 2023

Out of curiosity, could you include some examples of the type of code this enables?

@explocion
Copy link
Author

Of course! I was using ux to write embedded system traits, e.g., OutputPins<const N: usize>, which is a group of N output pins. The trait is defined as

pub trait OutputPins<const N: usize> {
  type Error;
  fn write_pins(&mut self, state: ??) -> Result<(), Self::Error>;
}

Then, what is a type safe way to fill in the ?? part? I come up with ux, and with this pull request, I can write

pub trait OutputPins<const N: usize> where Const<N>: ToUnsignedType {
  type Error;
  fn write_pins(&mut self, state: Unsigned<N>) -> Result<(), Self::Error>;
}

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

Successfully merging this pull request may close these issues.

2 participants