Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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<T>` | 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 |
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions changelog.d/20260414_replace_funty_with_platform_num.md
Original file line number Diff line number Diff line change
@@ -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
33 changes: 17 additions & 16 deletions src/constants.rs
Original file line number Diff line number Diff line change
@@ -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<T: LinkType> {
pub struct LinksConstants<T: LinkReference> {
pub index_part: T,
pub source_part: T,
pub target_part: T,
Expand All @@ -18,9 +19,9 @@ pub struct LinksConstants<T: LinkType> {
pub external_range: Option<RangeInclusive<T>>,
}

impl<T: LinkType> LinksConstants<T> {
impl<T: LinkReference> LinksConstants<T> {
fn default_target_part() -> T {
T::funty(2)
T::from_byte(2)
}

pub fn full_new(
Expand All @@ -29,17 +30,17 @@ impl<T: LinkType> LinksConstants<T> {
external: Option<RangeInclusive<T>>,
) -> 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,
}
}
Expand Down Expand Up @@ -79,9 +80,9 @@ impl<T: LinkType> LinksConstants<T> {

fn default_internal(external: bool) -> RangeInclusive<T> {
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
}
}

Expand All @@ -108,7 +109,7 @@ impl<T: LinkType> LinksConstants<T> {
}
}

impl<T: LinkType> Default for LinksConstants<T> {
impl<T: LinkReference> Default for LinksConstants<T> {
fn default() -> Self {
Self::new()
}
Expand Down
7 changes: 4 additions & 3 deletions src/converters.rs
Original file line number Diff line number Diff line change
@@ -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<T: LinkType>(&self, source: T) -> T {
pub fn convert<T: LinkReference>(&self, source: T) -> T {
Hybrid::external(source).as_inner()
}
}
Expand All @@ -13,7 +14,7 @@ impl AddrToRaw {
pub struct RawToAddr;

impl RawToAddr {
pub fn convert<T: LinkType>(&self, source: T) -> T {
pub fn convert<T: LinkReference>(&self, source: T) -> T {
Hybrid::external(source).abs()
}
}
16 changes: 9 additions & 7 deletions src/hybrid.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use crate::LinkType;
use platform_num::LinkReference;

#[derive(Debug, Clone, Copy, Hash, PartialOrd, PartialEq, Ord, Eq)]
pub struct Hybrid<T> {
value: T,
}

impl<T: LinkType> Hybrid<T> {
impl<T: LinkReference> Hybrid<T> {
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 {
Expand All @@ -26,23 +26,25 @@ impl<T: LinkType> Hybrid<T> {
}

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 {
self.value < Self::half() // || self.value == T::default()
}

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 {
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ mod constants;
mod converters;
mod flow;
mod hybrid;
mod link_type;
mod links;
mod point;
mod query;
Expand All @@ -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};
87 changes: 0 additions & 87 deletions src/link_type.rs

This file was deleted.

7 changes: 4 additions & 3 deletions src/links.rs
Original file line number Diff line number Diff line change
@@ -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),

Expand All @@ -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<T: LinkType> {
pub trait Links<T: LinkReference> {
fn constants_links(&self) -> LinksConstants<T>;

fn count_links(&self, query: &[T]) -> T;
Expand Down
Loading