uX
uX copied to clipboard
incr: added type dispatch
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.
Out of curiosity, could you include some examples of the type of code this enables?
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>;
}