Skip to content

Add TryFrom/TryInto bounds and FuntyPart-like functionality to LinkReference #144

@konard

Description

@konard

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:

  1. 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>
  2. 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>
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions