uX icon indicating copy to clipboard operation
uX copied to clipboard

incr: added type dispatch

Open explocion opened this issue 1 year ago • 2 comments

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.

explocion avatar Aug 06 '23 01:08 explocion

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

bbaldino avatar Aug 08 '23 21:08 bbaldino

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>;
}

explocion avatar Aug 09 '23 09:08 explocion