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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
bump: minor
---

### Added
- `TryFrom<T>` and `TryInto<T>` bounds (with `Error: Debug`) for all 12 integer types on `LinkReference`
- `from_byte(n: u8) -> Self` default method on `LinkReference` for creating small constants from `u8` values
- `Sized` bound on `LinkReference`
- Explicit `u128` support as a `LinkReference` type (enables referencing very large link address spaces)
4 changes: 2 additions & 2 deletions rust/Cargo.lock

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

70 changes: 64 additions & 6 deletions rust/src/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ for_each_integer_type!(max_value_impl);
/// A composite trait for types that can be used as link identifiers.
///
/// Combines [`Number`], `Unsigned`, [`ToSigned`], [`MaxValue`],
/// `FromPrimitive`, `Debug`, `Display`, `Hash`, `Send`, `Sync`,
/// and `'static`.
/// `FromPrimitive`, `TryFrom`/`TryInto` for all integer types,
/// `Debug`, `Display`, `Hash`, `Send`, `Sync`, and `'static`.
///
/// Implemented for `u8`, `u16`, `u32`, `u64`, and `usize`.
/// Implemented for `u8`, `u16`, `u32`, `u64`, `u128`, and `usize`.
///
/// # Design note
///
Expand All @@ -166,25 +166,83 @@ for_each_integer_type!(max_value_impl);
/// ```
#[rustfmt::skip]
pub trait LinkReference:
Number
Sized
+ Number
+ Unsigned
+ ToSigned
+ MaxValue
+ FromPrimitive
+ TryFrom<i8, Error: Debug>
+ TryFrom<u8, Error: Debug>
+ TryFrom<i16, Error: Debug>
+ TryFrom<u16, Error: Debug>
+ TryFrom<i32, Error: Debug>
+ TryFrom<u32, Error: Debug>
+ TryFrom<i64, Error: Debug>
+ TryFrom<u64, Error: Debug>
+ TryFrom<i128, Error: Debug>
+ TryFrom<u128, Error: Debug>
+ TryFrom<isize, Error: Debug>
+ TryFrom<usize, Error: Debug>
+ TryInto<i8, Error: Debug>
+ TryInto<u8, Error: Debug>
+ TryInto<i16, Error: Debug>
+ TryInto<u16, Error: Debug>
+ TryInto<i32, Error: Debug>
+ TryInto<u32, Error: Debug>
+ TryInto<i64, Error: Debug>
+ TryInto<u64, Error: Debug>
+ TryInto<i128, Error: Debug>
+ TryInto<u128, Error: Debug>
+ TryInto<isize, Error: Debug>
+ TryInto<usize, Error: Debug>
+ Debug
+ Display
+ Hash
+ Send
+ Sync
+ 'static {}
+ 'static
{
/// Creates a value of this type from a `u8`, panicking on overflow.
fn from_byte(n: u8) -> Self {
Self::try_from(n).unwrap_or_else(|e| {
panic!("LinkReference::from_byte({n}) failed: {e:?}")
})
}
}

#[rustfmt::skip]
impl<
All: Number
All: Sized
+ Number
+ Unsigned
+ ToSigned
+ MaxValue
+ FromPrimitive
+ TryFrom<i8, Error: Debug>
+ TryFrom<u8, Error: Debug>
+ TryFrom<i16, Error: Debug>
+ TryFrom<u16, Error: Debug>
+ TryFrom<i32, Error: Debug>
+ TryFrom<u32, Error: Debug>
+ TryFrom<i64, Error: Debug>
+ TryFrom<u64, Error: Debug>
+ TryFrom<i128, Error: Debug>
+ TryFrom<u128, Error: Debug>
+ TryFrom<isize, Error: Debug>
+ TryFrom<usize, Error: Debug>
+ TryInto<i8, Error: Debug>
+ TryInto<u8, Error: Debug>
+ TryInto<i16, Error: Debug>
+ TryInto<u16, Error: Debug>
+ TryInto<i32, Error: Debug>
+ TryInto<u32, Error: Debug>
+ TryInto<i64, Error: Debug>
+ TryInto<u64, Error: Debug>
+ TryInto<i128, Error: Debug>
+ TryInto<u128, Error: Debug>
+ TryInto<isize, Error: Debug>
+ TryInto<usize, Error: Debug>
+ Debug
+ Display
+ Hash
Expand Down
2 changes: 1 addition & 1 deletion rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! | [`SignedNumber`] | Extends [`Number`] with signed operations (`Signed + FromPrimitive`) |
//! | [`ToSigned`] | Converts an unsigned type to its signed counterpart (e.g. `u32` → `i32`) |
//! | [`MaxValue`] | Provides a `MAX` associated constant for every primitive integer type |
//! | [`LinkReference`] | Composite trait for link identifiers — unsigned, hashable, displayable, thread-safe |
//! | [`LinkReference`] | Composite trait for link identifiers — unsigned, hashable, displayable, thread-safe, with `TryFrom`/`TryInto` for all integer types |
//!
//! ## Example
//!
Expand Down
Loading
Loading