Repository navigation
Description
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>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):- This is a convenience method for creating small constants from
u8values - Can be provided as a default method on
LinkReferencesince all implementors already satisfyTryFrom<u8>
- This is a convenience method for creating small constants from
-
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 ecosystem
Related
- Double check we don't depend on any non stable features of rust and use all the latest best practices and versions of rust in the code doublets-rs#47 — Original issue driving this unification
- Port doublets to stable Rust, migrate deps to crates.io, update CI/CD doublets-rs#48 — PR with analysis of the trait incompatibility
Activity
Initial commit with task details
feat: add TryFrom/TryInto bounds, funty() method, and Sized bound to …