diff --git a/Cargo.lock b/Cargo.lock index e7ccac5..051aea6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,12 @@ version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + [[package]] name = "beef" version = "0.5.2" @@ -67,12 +73,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "getrandom" version = "0.4.2" @@ -156,17 +156,35 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "platform-data" -version = "0.1.0-beta.3" +version = "1.0.0" dependencies = [ "beef", - "funty", + "platform-num", "quickcheck", "quickcheck_macros", "thiserror", ] +[[package]] +name = "platform-num" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c4ca8e18138b1c90ad802aff931f946a0e6bd760c35af30f1ff2489489ab54a" +dependencies = [ + "num-traits", +] + [[package]] name = "prettyplease" version = "0.2.37" diff --git a/Cargo.toml b/Cargo.toml index c4bc808..09149ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ categories = ["data-structures"] [dependencies] beef = "0.5.2" -funty = "2.0.0" +platform-num = "0.8.0" thiserror = "2.0.18" [dev-dependencies] diff --git a/README.md b/README.md index 8a9beca..a2f8c1b 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ This crate provides core data types and traits for the [Links Platform](https:// The `platform-data` crate provides: -- **`LinkType`** — A trait defining the numeric types that can be used as link identifiers +- **`LinkReference`** — A trait (from `platform-num`) defining the numeric types that can be used as link identifiers - **`Links`** — The core trait for CRUD operations on doublet links storage - **`Flow`** — Control flow type for iteration operations (Continue/Break) - **`Query`** — A wrapper for link queries using copy-on-write semantics @@ -115,7 +115,7 @@ assert!(external.is_external()); ### Implementing the Links trait ```rust -use platform_data::{Links, LinkType, LinksConstants, Flow, Error, ReadHandler, WriteHandler}; +use platform_data::{Links, LinkReference, LinksConstants, Flow, Error, ReadHandler, WriteHandler}; // The Links trait provides CRUD operations for doublet links: // - constants_links() - get storage configuration @@ -132,7 +132,7 @@ use platform_data::{Links, LinkType, LinksConstants, Flow, Error, ReadHandler, W | Type | Description | |------|-------------| -| `LinkType` | Trait bound for numeric types usable as link identifiers (unsigned integers) | +| `LinkReference` | Trait bound (from `platform-num`) for numeric types usable as link identifiers (unsigned integers) | | `Links` | Main trait defining CRUD operations for links storage | | `Flow` | Control flow enum: `Continue` or `Break` for iteration control | | `Query<'a, T>` | Copy-on-write query wrapper for efficient link queries | @@ -162,7 +162,7 @@ This crate requires **Rust 1.85 or later** (stable toolchain, edition 2024). ## Dependencies - [beef](https://crates.io/crates/beef) — Faster and more compact Cow implementation -- [funty](https://crates.io/crates/funty) — Fundamental type unification +- [platform-num](https://crates.io/crates/platform-num) — Numeric traits for the Links Platform (`LinkReference`, `WrappingAdd`, etc.) - [thiserror](https://crates.io/crates/thiserror) — Derive macro for error types ## Documentation diff --git a/changelog.d/20260414_replace_funty_with_platform_num.md b/changelog.d/20260414_replace_funty_with_platform_num.md new file mode 100644 index 0000000..f08fa5b --- /dev/null +++ b/changelog.d/20260414_replace_funty_with_platform_num.md @@ -0,0 +1,16 @@ +--- +bump: major +--- + +### Changed +- Replaced `funty` dependency with `platform-num` 0.8.0 (`LinkReference` trait) +- Replaced all `LinkType` bounds with `LinkReference` from `platform-num` +- Replaced `FuntyPart::funty(n)` calls with `LinkReference::from_byte(n)` +- Simplified all generic bounds from `T: LinkReference + WrappingAdd` to `T: LinkReference` (`WrappingArithmetic` is now a supertrait of `LinkReference` in `platform-num` 0.8.0) + +### Removed +- Removed `funty` dependency +- Removed `num-traits` dependency (re-exported by `platform-num`) +- Removed `LinkType` trait entirely (replaced by `LinkReference`) +- Removed `FuntyPart` trait (replaced by `LinkReference::from_byte`) +- Removed `link_type.rs` module diff --git a/src/constants.rs b/src/constants.rs index 1c0679a..35b21bd 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -1,9 +1,10 @@ use std::ops::RangeInclusive; -use crate::{Hybrid, LinkType}; +use crate::Hybrid; +use platform_num::LinkReference; #[derive(Clone, Eq, PartialEq, Debug)] -pub struct LinksConstants { +pub struct LinksConstants { pub index_part: T, pub source_part: T, pub target_part: T, @@ -18,9 +19,9 @@ pub struct LinksConstants { pub external_range: Option>, } -impl LinksConstants { +impl LinksConstants { fn default_target_part() -> T { - T::funty(2) + T::from_byte(2) } pub fn full_new( @@ -29,17 +30,17 @@ impl LinksConstants { external: Option>, ) -> Self { Self { - index_part: T::funty(0), - source_part: T::funty(1), + index_part: T::from_byte(0), + source_part: T::from_byte(1), target_part, - null: T::funty(0), + null: T::from_byte(0), r#continue: *internal.end(), - r#break: *internal.end() - T::funty(1), - skip: *internal.end() - T::funty(2), - any: *internal.end() - T::funty(3), - itself: *internal.end() - T::funty(4), - error: *internal.end() - T::funty(5), - internal_range: *internal.start()..=*internal.end() - T::funty(6), + r#break: *internal.end() - T::from_byte(1), + skip: *internal.end() - T::from_byte(2), + any: *internal.end() - T::from_byte(3), + itself: *internal.end() - T::from_byte(4), + error: *internal.end() - T::from_byte(5), + internal_range: *internal.start()..=*internal.end() - T::from_byte(6), external_range: external, } } @@ -79,9 +80,9 @@ impl LinksConstants { fn default_internal(external: bool) -> RangeInclusive { if external { - T::funty(1)..=Hybrid::half() + T::from_byte(1)..=Hybrid::half() } else { - T::funty(1)..=T::MAX + T::from_byte(1)..=T::MAX } } @@ -108,7 +109,7 @@ impl LinksConstants { } } -impl Default for LinksConstants { +impl Default for LinksConstants { fn default() -> Self { Self::new() } diff --git a/src/converters.rs b/src/converters.rs index 5e3b966..36cd89f 100644 --- a/src/converters.rs +++ b/src/converters.rs @@ -1,10 +1,11 @@ -use crate::{Hybrid, LinkType}; +use crate::Hybrid; +use platform_num::LinkReference; #[derive(Default)] pub struct AddrToRaw; impl AddrToRaw { - pub fn convert(&self, source: T) -> T { + pub fn convert(&self, source: T) -> T { Hybrid::external(source).as_inner() } } @@ -13,7 +14,7 @@ impl AddrToRaw { pub struct RawToAddr; impl RawToAddr { - pub fn convert(&self, source: T) -> T { + pub fn convert(&self, source: T) -> T { Hybrid::external(source).abs() } } diff --git a/src/hybrid.rs b/src/hybrid.rs index 8c45d05..7766cb7 100644 --- a/src/hybrid.rs +++ b/src/hybrid.rs @@ -1,18 +1,18 @@ -use crate::LinkType; +use platform_num::LinkReference; #[derive(Debug, Clone, Copy, Hash, PartialOrd, PartialEq, Ord, Eq)] pub struct Hybrid { value: T, } -impl Hybrid { +impl Hybrid { pub const fn new(value: T) -> Self { Self::internal(value) } #[must_use] pub fn half() -> T { - T::MAX / T::funty(2) + T::MAX / T::from_byte(2) } pub fn external(value: T) -> Self { @@ -26,11 +26,11 @@ impl Hybrid { } fn extend_value(value: T) -> T { - (T::MAX - value).wrapping_add(T::funty(1)) + (T::MAX - value).wrapping_add(&T::from_byte(1)) } pub fn is_zero(&self) -> bool { - self.value == T::funty(0) + self.value == T::from_byte(0) } pub fn is_internal(&self) -> bool { @@ -38,11 +38,13 @@ impl Hybrid { } pub fn is_external(&self) -> bool { - !self.is_internal() || self.value == T::funty(0) + !self.is_internal() || self.value == T::from_byte(0) } pub fn abs(&self) -> T { - self.value.wrapping_add(T::funty(1)).wrapping_add(T::MAX) + self.value + .wrapping_add(&T::from_byte(1)) + .wrapping_add(&T::MAX) } pub const fn as_inner(&self) -> T { diff --git a/src/lib.rs b/src/lib.rs index fe865e7..43d006f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,6 @@ mod constants; mod converters; mod flow; mod hybrid; -mod link_type; mod links; mod point; mod query; @@ -11,7 +10,7 @@ pub use constants::LinksConstants; pub use converters::{AddrToRaw, RawToAddr}; pub use flow::Flow; pub use hybrid::Hybrid; -pub use link_type::LinkType; pub use links::{Error, Links, ReadHandler, WriteHandler}; +pub use platform_num::LinkReference; pub use point::{Point, PointIter}; pub use query::{Query, ToQuery}; diff --git a/src/link_type.rs b/src/link_type.rs deleted file mode 100644 index 84e1d26..0000000 --- a/src/link_type.rs +++ /dev/null @@ -1,87 +0,0 @@ -use funty::Unsigned; -use std::{ - convert::{TryFrom, TryInto}, - fmt::Debug, -}; - -/// Trait for creating small numeric values from u8. -/// -/// This trait provides a convenient way to create numeric types from small u8 values, -/// which is commonly needed when working with link constants and indices. -pub trait FuntyPart: Sized + TryFrom { - /// Create a value from a u8. Panics if the conversion fails. - fn funty(n: u8) -> Self; -} - -impl> FuntyPart for All -where - >::Error: Debug, -{ - fn funty(n: u8) -> Self { - All::try_from(n).expect("conversion from u8 should succeed for all unsigned types") - } -} - -/// Trait bound for numeric types that can be used as link identifiers. -/// -/// This trait combines several requirements: -/// - Must be an unsigned integer type (via `Unsigned`) -/// - Must support creation from small values (via `FuntyPart`) -/// - Must support conversions to/from various integer types -pub trait LinkType: - Unsigned - + FuntyPart - + TryFrom - + TryFrom - + TryFrom - + TryFrom - + TryFrom - + TryFrom - + TryFrom - + TryFrom - + TryFrom - + TryFrom - + TryFrom - + TryFrom - + TryInto - + TryInto - + TryInto - + TryInto - + TryInto - + TryInto - + TryInto - + TryInto - + TryInto - + TryInto - + TryInto - + TryInto -{ -} - -impl LinkType for All where - All: TryFrom - + TryFrom - + TryFrom - + TryFrom - + TryFrom - + TryFrom - + TryFrom - + TryFrom - + TryFrom - + TryFrom - + TryFrom - + TryFrom - + TryInto - + TryInto - + TryInto - + TryInto - + TryInto - + TryInto - + TryInto - + TryInto - + TryInto - + TryInto - + TryInto - + TryInto -{ -} diff --git a/src/links.rs b/src/links.rs index 7ccc94f..5334990 100644 --- a/src/links.rs +++ b/src/links.rs @@ -1,8 +1,9 @@ -use crate::{Flow, LinkType, LinksConstants}; +use crate::{Flow, LinksConstants}; +use platform_num::LinkReference; use std::{borrow::Cow, error, io}; #[derive(thiserror::Error, Debug)] -pub enum Error<'a, T: LinkType> { +pub enum Error<'a, T: LinkReference> { #[error("link {0} does not exist.")] NotExists(T), @@ -26,7 +27,7 @@ pub type ReadHandler<'a, T> = &'a mut dyn FnMut(&[T]) -> Flow; pub type WriteHandler<'a, T> = &'a mut dyn FnMut(&[T], &[T]) -> Flow; -pub trait Links { +pub trait Links { fn constants_links(&self) -> LinksConstants; fn count_links(&self, query: &[T]) -> T;