Summary
To unify the trait ecosystem across platform-data, platform-trees, and doublets, LinkReference in platform-num needs to include additional bounds that are currently provided separately by funty (in platform-data) and num-traits (in platform-trees).
Background
Currently, three different trait hierarchies define "unsigned integer suitable for link storage":
| Crate |
Trait |
Key bounds |
platform-num 0.6.0 |
LinkReference |
Number + Unsigned + ToSigned + MaxValue + FromPrimitive + Debug + Display + Hash + Send + Sync + 'static |
platform-data 1.0.0 |
LinkType |
funty::Unsigned + FuntyPart + TryFrom/TryInto<all integer types> |
platform-trees 0.3.3 |
LinkType |
Number + num_traits::Unsigned + TryFrom<u8> + FromPrimitive |
These traits are implemented for the same concrete types (u8, u16, u32, u64, usize) but are incompatible at the generic level because they use different supertrait hierarchies.
The goal is to make LinkReference the single unified trait that both platform-data and platform-trees can use, eliminating the need for funty and reducing trait fragmentation.
Proposed changes to LinkReference
Add the following bounds to LinkReference:
-
TryFrom<T> and TryInto<T> for all integer types (with Error: Debug):
TryFrom<i8>, TryFrom<u8>, TryFrom<i16>, TryFrom<u16>, TryFrom<i32>, TryFrom<u32>, TryFrom<i64>, TryFrom<u64>, TryFrom<i128>, TryFrom<u128>, TryFrom<isize>, TryFrom<usize>
TryInto<i8>, TryInto<u8>, TryInto<i16>, TryInto<u16>, TryInto<i32>, TryInto<u32>, TryInto<i64>, TryInto<u64>, TryInto<i128>, TryInto<u128>, TryInto<isize>, TryInto<usize>
-
A funty(n: u8) -> Self method (equivalent to FuntyPart from platform-data):
- This is a convenience method for creating small constants from
u8 values
- Can be provided as a default method on
LinkReference since all implementors already satisfy TryFrom<u8>
-
Sized bound (required by platform-trees's LinkType)
All these bounds are already satisfied by the concrete types that implement LinkReference (u8, u16, u32, u64, usize), so this is a backwards-compatible addition.
Expected outcome
After this change:
platform-data can replace funty::Unsigned + FuntyPart with LinkReference (see linksplatform/data-rs issue)
platform-trees can replace Number + Unsigned + TryFrom<u8> + FromPrimitive with LinkReference (see linksplatform/trees-rs issue)
doublets-rs can use a single T: LinkReference bound instead of T: data::LinkType + trees::LinkType
funty dependency is eliminated from the ecosystem
Related
Summary
To unify the trait ecosystem across
platform-data,platform-trees, anddoublets,LinkReferenceinplatform-numneeds to include additional bounds that are currently provided separately byfunty(inplatform-data) andnum-traits(inplatform-trees).Background
Currently, three different trait hierarchies define "unsigned integer suitable for link storage":
platform-num0.6.0LinkReferenceNumber + Unsigned + ToSigned + MaxValue + FromPrimitive + Debug + Display + Hash + Send + Sync + 'staticplatform-data1.0.0LinkTypefunty::Unsigned + FuntyPart + TryFrom/TryInto<all integer types>platform-trees0.3.3LinkTypeNumber + num_traits::Unsigned + TryFrom<u8> + FromPrimitiveThese traits are implemented for the same concrete types (
u8,u16,u32,u64,usize) but are incompatible at the generic level because they use different supertrait hierarchies.The goal is to make
LinkReferencethe single unified trait that bothplatform-dataandplatform-treescan use, eliminating the need forfuntyand reducing trait fragmentation.Proposed changes to
LinkReferenceAdd the following bounds to
LinkReference:TryFrom<T>andTryInto<T>for all integer types (withError: Debug):TryFrom<i8>,TryFrom<u8>,TryFrom<i16>,TryFrom<u16>,TryFrom<i32>,TryFrom<u32>,TryFrom<i64>,TryFrom<u64>,TryFrom<i128>,TryFrom<u128>,TryFrom<isize>,TryFrom<usize>TryInto<i8>,TryInto<u8>,TryInto<i16>,TryInto<u16>,TryInto<i32>,TryInto<u32>,TryInto<i64>,TryInto<u64>,TryInto<i128>,TryInto<u128>,TryInto<isize>,TryInto<usize>A
funty(n: u8) -> Selfmethod (equivalent toFuntyPartfromplatform-data):u8valuesLinkReferencesince all implementors already satisfyTryFrom<u8>Sizedbound (required byplatform-trees'sLinkType)All these bounds are already satisfied by the concrete types that implement
LinkReference(u8,u16,u32,u64,usize), so this is a backwards-compatible addition.Expected outcome
After this change:
platform-datacan replacefunty::Unsigned + FuntyPartwithLinkReference(see linksplatform/data-rs issue)platform-treescan replaceNumber + Unsigned + TryFrom<u8> + FromPrimitivewithLinkReference(see linksplatform/trees-rs issue)doublets-rscan use a singleT: LinkReferencebound instead ofT: data::LinkType + trees::LinkTypefuntydependency is eliminated from the ecosystemRelated