Skip to content

Commit 3725de0

Browse files
authored
Merge pull request #17 from linksplatform/issue-16-3373fe2814a2
feat!: replace funty with platform-num, remove LinkType
2 parents ebf2ade + c71ed2b commit 3725de0

10 files changed

Lines changed: 82 additions & 131 deletions

File tree

Cargo.lock

Lines changed: 26 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ categories = ["data-structures"]
1414

1515
[dependencies]
1616
beef = "0.5.2"
17-
funty = "2.0.0"
17+
platform-num = "0.8.0"
1818
thiserror = "2.0.18"
1919

2020
[dev-dependencies]

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This crate provides core data types and traits for the [Links Platform](https://
1313

1414
The `platform-data` crate provides:
1515

16-
- **`LinkType`** — A trait defining the numeric types that can be used as link identifiers
16+
- **`LinkReference`** — A trait (from `platform-num`) defining the numeric types that can be used as link identifiers
1717
- **`Links`** — The core trait for CRUD operations on doublet links storage
1818
- **`Flow`** — Control flow type for iteration operations (Continue/Break)
1919
- **`Query`** — A wrapper for link queries using copy-on-write semantics
@@ -115,7 +115,7 @@ assert!(external.is_external());
115115
### Implementing the Links trait
116116

117117
```rust
118-
use platform_data::{Links, LinkType, LinksConstants, Flow, Error, ReadHandler, WriteHandler};
118+
use platform_data::{Links, LinkReference, LinksConstants, Flow, Error, ReadHandler, WriteHandler};
119119

120120
// The Links trait provides CRUD operations for doublet links:
121121
// - constants_links() - get storage configuration
@@ -132,7 +132,7 @@ use platform_data::{Links, LinkType, LinksConstants, Flow, Error, ReadHandler, W
132132

133133
| Type | Description |
134134
|------|-------------|
135-
| `LinkType` | Trait bound for numeric types usable as link identifiers (unsigned integers) |
135+
| `LinkReference` | Trait bound (from `platform-num`) for numeric types usable as link identifiers (unsigned integers) |
136136
| `Links<T>` | Main trait defining CRUD operations for links storage |
137137
| `Flow` | Control flow enum: `Continue` or `Break` for iteration control |
138138
| `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).
162162
## Dependencies
163163

164164
- [beef](https://crates.io/crates/beef) — Faster and more compact Cow implementation
165-
- [funty](https://crates.io/crates/funty)Fundamental type unification
165+
- [platform-num](https://crates.io/crates/platform-num)Numeric traits for the Links Platform (`LinkReference`, `WrappingAdd`, etc.)
166166
- [thiserror](https://crates.io/crates/thiserror) — Derive macro for error types
167167

168168
## Documentation
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
bump: major
3+
---
4+
5+
### Changed
6+
- Replaced `funty` dependency with `platform-num` 0.8.0 (`LinkReference` trait)
7+
- Replaced all `LinkType` bounds with `LinkReference` from `platform-num`
8+
- Replaced `FuntyPart::funty(n)` calls with `LinkReference::from_byte(n)`
9+
- Simplified all generic bounds from `T: LinkReference + WrappingAdd` to `T: LinkReference` (`WrappingArithmetic` is now a supertrait of `LinkReference` in `platform-num` 0.8.0)
10+
11+
### Removed
12+
- Removed `funty` dependency
13+
- Removed `num-traits` dependency (re-exported by `platform-num`)
14+
- Removed `LinkType` trait entirely (replaced by `LinkReference`)
15+
- Removed `FuntyPart` trait (replaced by `LinkReference::from_byte`)
16+
- Removed `link_type.rs` module

src/constants.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use std::ops::RangeInclusive;
22

3-
use crate::{Hybrid, LinkType};
3+
use crate::Hybrid;
4+
use platform_num::LinkReference;
45

56
#[derive(Clone, Eq, PartialEq, Debug)]
6-
pub struct LinksConstants<T: LinkType> {
7+
pub struct LinksConstants<T: LinkReference> {
78
pub index_part: T,
89
pub source_part: T,
910
pub target_part: T,
@@ -18,9 +19,9 @@ pub struct LinksConstants<T: LinkType> {
1819
pub external_range: Option<RangeInclusive<T>>,
1920
}
2021

21-
impl<T: LinkType> LinksConstants<T> {
22+
impl<T: LinkReference> LinksConstants<T> {
2223
fn default_target_part() -> T {
23-
T::funty(2)
24+
T::from_byte(2)
2425
}
2526

2627
pub fn full_new(
@@ -29,17 +30,17 @@ impl<T: LinkType> LinksConstants<T> {
2930
external: Option<RangeInclusive<T>>,
3031
) -> Self {
3132
Self {
32-
index_part: T::funty(0),
33-
source_part: T::funty(1),
33+
index_part: T::from_byte(0),
34+
source_part: T::from_byte(1),
3435
target_part,
35-
null: T::funty(0),
36+
null: T::from_byte(0),
3637
r#continue: *internal.end(),
37-
r#break: *internal.end() - T::funty(1),
38-
skip: *internal.end() - T::funty(2),
39-
any: *internal.end() - T::funty(3),
40-
itself: *internal.end() - T::funty(4),
41-
error: *internal.end() - T::funty(5),
42-
internal_range: *internal.start()..=*internal.end() - T::funty(6),
38+
r#break: *internal.end() - T::from_byte(1),
39+
skip: *internal.end() - T::from_byte(2),
40+
any: *internal.end() - T::from_byte(3),
41+
itself: *internal.end() - T::from_byte(4),
42+
error: *internal.end() - T::from_byte(5),
43+
internal_range: *internal.start()..=*internal.end() - T::from_byte(6),
4344
external_range: external,
4445
}
4546
}
@@ -79,9 +80,9 @@ impl<T: LinkType> LinksConstants<T> {
7980

8081
fn default_internal(external: bool) -> RangeInclusive<T> {
8182
if external {
82-
T::funty(1)..=Hybrid::half()
83+
T::from_byte(1)..=Hybrid::half()
8384
} else {
84-
T::funty(1)..=T::MAX
85+
T::from_byte(1)..=T::MAX
8586
}
8687
}
8788

@@ -108,7 +109,7 @@ impl<T: LinkType> LinksConstants<T> {
108109
}
109110
}
110111

111-
impl<T: LinkType> Default for LinksConstants<T> {
112+
impl<T: LinkReference> Default for LinksConstants<T> {
112113
fn default() -> Self {
113114
Self::new()
114115
}

src/converters.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use crate::{Hybrid, LinkType};
1+
use crate::Hybrid;
2+
use platform_num::LinkReference;
23

34
#[derive(Default)]
45
pub struct AddrToRaw;
56

67
impl AddrToRaw {
7-
pub fn convert<T: LinkType>(&self, source: T) -> T {
8+
pub fn convert<T: LinkReference>(&self, source: T) -> T {
89
Hybrid::external(source).as_inner()
910
}
1011
}
@@ -13,7 +14,7 @@ impl AddrToRaw {
1314
pub struct RawToAddr;
1415

1516
impl RawToAddr {
16-
pub fn convert<T: LinkType>(&self, source: T) -> T {
17+
pub fn convert<T: LinkReference>(&self, source: T) -> T {
1718
Hybrid::external(source).abs()
1819
}
1920
}

src/hybrid.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
use crate::LinkType;
1+
use platform_num::LinkReference;
22

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

8-
impl<T: LinkType> Hybrid<T> {
8+
impl<T: LinkReference> Hybrid<T> {
99
pub const fn new(value: T) -> Self {
1010
Self::internal(value)
1111
}
1212

1313
#[must_use]
1414
pub fn half() -> T {
15-
T::MAX / T::funty(2)
15+
T::MAX / T::from_byte(2)
1616
}
1717

1818
pub fn external(value: T) -> Self {
@@ -26,23 +26,25 @@ impl<T: LinkType> Hybrid<T> {
2626
}
2727

2828
fn extend_value(value: T) -> T {
29-
(T::MAX - value).wrapping_add(T::funty(1))
29+
(T::MAX - value).wrapping_add(&T::from_byte(1))
3030
}
3131

3232
pub fn is_zero(&self) -> bool {
33-
self.value == T::funty(0)
33+
self.value == T::from_byte(0)
3434
}
3535

3636
pub fn is_internal(&self) -> bool {
3737
self.value < Self::half() // || self.value == T::default()
3838
}
3939

4040
pub fn is_external(&self) -> bool {
41-
!self.is_internal() || self.value == T::funty(0)
41+
!self.is_internal() || self.value == T::from_byte(0)
4242
}
4343

4444
pub fn abs(&self) -> T {
45-
self.value.wrapping_add(T::funty(1)).wrapping_add(T::MAX)
45+
self.value
46+
.wrapping_add(&T::from_byte(1))
47+
.wrapping_add(&T::MAX)
4648
}
4749

4850
pub const fn as_inner(&self) -> T {

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ mod constants;
22
mod converters;
33
mod flow;
44
mod hybrid;
5-
mod link_type;
65
mod links;
76
mod point;
87
mod query;
@@ -11,7 +10,7 @@ pub use constants::LinksConstants;
1110
pub use converters::{AddrToRaw, RawToAddr};
1211
pub use flow::Flow;
1312
pub use hybrid::Hybrid;
14-
pub use link_type::LinkType;
1513
pub use links::{Error, Links, ReadHandler, WriteHandler};
14+
pub use platform_num::LinkReference;
1615
pub use point::{Point, PointIter};
1716
pub use query::{Query, ToQuery};

src/link_type.rs

Lines changed: 0 additions & 87 deletions
This file was deleted.

src/links.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use crate::{Flow, LinkType, LinksConstants};
1+
use crate::{Flow, LinksConstants};
2+
use platform_num::LinkReference;
23
use std::{borrow::Cow, error, io};
34

45
#[derive(thiserror::Error, Debug)]
5-
pub enum Error<'a, T: LinkType> {
6+
pub enum Error<'a, T: LinkReference> {
67
#[error("link {0} does not exist.")]
78
NotExists(T),
89

@@ -26,7 +27,7 @@ pub type ReadHandler<'a, T> = &'a mut dyn FnMut(&[T]) -> Flow;
2627

2728
pub type WriteHandler<'a, T> = &'a mut dyn FnMut(&[T], &[T]) -> Flow;
2829

29-
pub trait Links<T: LinkType> {
30+
pub trait Links<T: LinkReference> {
3031
fn constants_links(&self) -> LinksConstants<T>;
3132

3233
fn count_links(&self, query: &[T]) -> T;

0 commit comments

Comments
 (0)