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
7 changes: 7 additions & 0 deletions changelog.d/20260323_rename_traits.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: minor
---

### Changed
- Rename Rust traits to use full English words: `Num` → `Number`, `SignNum` → `SignedNumber`, `LinkType` → `LinkReference`
- Add documentation comments to all public traits with examples
2 changes: 1 addition & 1 deletion rust/Cargo.lock

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

22 changes: 11 additions & 11 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ Crates.io package: [platform-num](https://crates.io/crates/platform-num)
This crate provides a set of numeric traits used throughout the
LinksPlatform ecosystem:

- **`Num`** — A base trait combining `PrimInt`, `Default`, `Debug`,
- **`Number`** — A base trait combining `PrimInt`, `Default`, `Debug`,
`AsPrimitive<usize>`, and `ToPrimitive`. Implemented for all
primitive integer types.
- **`SignNum`** — Extends `Num` with signed number operations
- **`SignedNumber`** — Extends `Number` with signed number operations
(`Signed`, `FromPrimitive`). Implemented for signed integer types.
- **`ToSigned`** — Converts unsigned types to their signed
counterparts (e.g. `u32` → `i32`).
- **`MaxValue`** — Provides a `MAX` associated constant for all
primitive integer types.
- **`LinkType`** — A composite trait for types that can be used as
link identifiers: `Num + Unsigned + ToSigned + MaxValue +
- **`LinkReference`** — A composite trait for types that can be used as
link identifiers: `Number + Unsigned + ToSigned + MaxValue +
FromPrimitive + Debug + Display + Hash + Send + Sync + 'static`.
Implemented for `u8`, `u16`, `u32`, `u64`, and `usize`.

Expand All @@ -36,17 +36,17 @@ Add to your `Cargo.toml`:

```toml
[dependencies]
platform-num = "0.2"
platform-num = "0.4"
```

## Usage

### Using `LinkType` as a generic constraint
### Using `LinkReference` as a generic constraint

```rust
use platform_num::LinkType;
use platform_num::LinkReference;

fn create_link<T: LinkType>(source: T, target: T) -> (T, T) {
fn create_link<T: LinkReference>(source: T, target: T) -> (T, T) {
(source, target)
}

Expand Down Expand Up @@ -76,13 +76,13 @@ fn get_max<T: MaxValue>() -> T {
assert_eq!(get_max::<u64>(), u64::MAX);
```

### Using `Num` for generic numeric operations
### Using `Number` for generic numeric operations

```rust
use platform_num::Num;
use platform_num::Number;
use num_traits::AsPrimitive;

fn to_usize<T: Num>(val: T) -> usize {
fn to_usize<T: Number>(val: T) -> usize {
val.as_()
}

Expand Down
Loading
Loading