-
Notifications
You must be signed in to change notification settings - Fork 85
Open
Milestone
Description
An investigation is necessary to see if we can safely allow customization of key sizes. Something along the following lines should work:
pub trait Key {
type Index: KeyIndex;
type Version: KeyVersion;
}
pub trait KeyIndex: private::Sealed {
#[doc(hidden)]
type T: UInt;
}
pub trait KeyVersion: private::Sealed {
#[doc(hidden)]
type T: UInt;
#[doc(hidden)]
type NonZeroT: NonZeroUInt;
}
// All the ops needed for implementing.
#[doc(hidden)]
pub trait NonZeroUInt: Copy + PartialEq + Eq /* ... */ {}
#[doc(hidden)]
pub trait UInt: Copy + PartialEq + Eq /* ... */ {}
mod private {
pub trait Sealed {}
}
// Implement all for u8, u16, u32, u64, u128...
impl UInt for u32 {}
impl NonZeroUInt for NonZeroU32 {}
impl KeyIndex for u32 {
type T = u32;
}
impl KeyVersion for u32 {
type T = u32;
type NonZeroT = NonZeroU32;
}
impl private::Sealed for u32 {}
pub struct KeyData<I: KeyIndex, V: KeyVersion> {
idx: I::T,
version: V::NonZeroT,
}
// Allow following syntax:
new_key_type! {
struct DefaultKey; // u32 index/version
struct SmallKey(u16, u16); // u16 index/version
struct HardenedKey(u32, u128); // u32 index, u128 version
}lazytype, joseluis, petoknm, matszczygiel, bbb651 and 1 more
Metadata
Metadata
Assignees
Labels
No labels