-
-
Notifications
You must be signed in to change notification settings - Fork 2
Add Rust tuple conversion support with macro for all sizes (2-12) #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: #200
Implement From trait conversions for Rust tuples (2-tuple through 4-tuple) to LiNo<String>, enabling ergonomic syntax similar to C#'s tuple conversion. Features: - Support for string tuples: (&str, &str), (String, String), etc. - Support for mixed tuples: (&str, LiNo<String>), etc. - Support for LiNo tuples: (LiNo<String>, LiNo<String>), etc. - Anonymous links from multiple LiNo values - Comprehensive test coverage with 16 new tests This brings Rust implementation closer to feature parity with C#, allowing developers to create links using native Rust tuple syntax. Fixes #200 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Create comprehensive example showing: - Basic 2-tuple, 3-tuple, and 4-tuple conversions - Mixed tuples with LiNo values - Anonymous links from LiNo tuples - Complex nested structures - Ergonomic collection creation - Owned String tuple conversion Example can be run with: cargo run --example tuple_conversion Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This reverts commit ba66e7e.
|
|
Resolve conflicts. Can we support all tuple sizes all at once? Do we need marco for that? |
|
🤖 AI Work Session Started Starting automated work session at 2026-01-16T12:19:53.892Z The PR has been converted to draft mode while work is in progress. This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback. |
Resolve merge conflicts from Rust project restructuring: - Move tuple_conversion.rs to new location: rust/links-notation/examples/ - Move tuple_tests.rs to new location: rust/links-notation/tests/ Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace manually written From implementations for tuples with a macro-based approach (impl_tuple_from!) that generates all necessary implementations for tuples of sizes 2 through 12, following Rust's standard library convention. Changes: - Replace 12 manual impl From blocks with macro-generated implementations - Support 4 conversion types for each tuple size: - All &str: first becomes ID, rest become values - All String: same pattern with owned strings - &str ID with LiNo values: for nested link structures - All LiNo: creates anonymous links (no ID) - Add 16 new tests for tuple sizes 5-12 - Update README documentation with new tuple size support This reduces code duplication while providing compile-time type safety for all supported tuple sizes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Changes MadeI've addressed the feedback: 1. Resolved Merge ConflictsMerged the latest changes from main which included the Rust project restructuring (moving from 2. Implemented Macro for All Tuple Sizes (2-12)As requested, I replaced the manual macro_rules! impl_tuple_from {
// ... generates all implementations
}
// Generate implementations for tuples of sizes 2 through 12
impl_tuple_from!(2);
impl_tuple_from!(3);
// ... up to
impl_tuple_from!(12);This follows the Rust standard library convention of supporting tuples up to 12 elements. The macro generates 44 total implementations (4 types × 11 sizes):
Test Results
The PR is now ready for review. |
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
|
So we cannot support any tuple length? Once and for all? |
|
🤖 AI Work Session Started Starting automated work session at 2026-01-17T00:03:57.382Z The PR has been converted to draft mode while work is in progress. This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback. |
Rust does not support variadic generics (a long-requested feature still
in pre-RFC stage), which means we cannot implement From for tuples of
arbitrary length. This is a fundamental Rust limitation - even the
standard library only implements traits for tuples up to 12 elements.
This commit adds alternative APIs for creating links when tuple
conversion is insufficient:
1. LinkBuilder - fluent builder API for constructing links:
```rust
LinkBuilder::new()
.id("myLink")
.value("v1")
.values(vec!["v2", "v3"])
.lino(nested_link)
.build()
```
2. Vec-based From implementations:
- From<Vec<&str>> for anonymous links
- From<Vec<String>> for anonymous links
- From<Vec<LiNo<String>>> for anonymous links
- From<(&str, Vec<&str>)> for named links
- From<(String, Vec<String>)> for named links
- From<(&str, Vec<LiNo<String>>)> for named links
- From<(String, Vec<LiNo<String>>)> for named links
3. Static methods on LiNo:
- LiNo::new(id, values) - create named link
- LiNo::anonymous(values) - create anonymous link
- LiNo::reference(value) - create reference
These APIs support creating links with any number of values,
addressing the user's question about supporting "any tuple length,
once and for all."
For reference on Rust's variadic generics status:
- rust-lang/rfcs#376
- rust-lang/rust#10124
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Response to Question: Can we support any tuple length?Short answer: No, not with Rust's current type system. Why Rust Can't Support Arbitrary-Length TuplesRust does not have variadic generics, which would be required to implement Even the Rust standard library faces this same limitation - traits like Status of variadic generics in Rust:
Solution: Alternative APIs for Arbitrary-Length LinksI've added three alternative approaches that do support any number of values: 1. Vec-based Conversions// Anonymous link with any number of values
let values: Vec<&str> = vec!["v1", "v2", "v3", ..., "v100"];
let link: LiNo<String> = values.into();
// Named link with any number of values
let link: LiNo<String> = ("myId", values).into();2. LinkBuilder (Fluent API)let link: LiNo<String> = LinkBuilder::new()
.id("myLink")
.value("v1")
.value("v2")
.values(vec!["v3", "v4", "v5"])
.lino(nested_link)
.build();3. Static Methodslet values: Vec<LiNo<String>> = (1..=100)
.map(|i| LiNo::Ref(format!("item{}", i)))
.collect();
let link = LiNo::new(Some("hundred".to_string()), values);Summary
The tuple conversion (2-12 elements) covers the vast majority of use cases with the most ergonomic syntax. For cases needing more elements or runtime-determined sizes, the new APIs provide full support. All 275 tests pass ✅ |
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
Summary
This PR implements Rust-specific tuple conversion support for Links Notation, enabling ergonomic link creation using native Rust tuple syntax. The implementation uses a macro-based approach to support all tuple sizes from 2 to 12 (following Rust's standard library convention), plus alternative APIs for arbitrary-length link creation.
Changes
Core Implementation
impl_tuple_from!macro inrust/links-notation/src/lib.rsthat generatesFromtrait implementations for tuples&str:("id", "v1", "v2", ...)→(id: v1 v2 ...)String:(id.to_string(), v1.to_string(), ...)→(id: v1 v2 ...)&strID withLiNovalues:("id", lino1, lino2, ...)→(id: <lino1> <lino2> ...)LiNo:(lino1, lino2, ...)→(<lino1> <lino2> ...)(anonymous link)Alternative APIs for Arbitrary-Length Links
Since Rust lacks variadic generics, we provide alternative APIs for creating links with any number of values:
1. LinkBuilder (Fluent API)
2. Vec-based Conversions
3. Static Methods
Test Coverage
rust/links-notation/tests/tuple_tests.rsDocumentation
rust/links-notation/README.mdwith comprehensive tuple conversion sectionWhy Can't We Support Any Tuple Length?
Rust does not have variadic generics (a feature still in pre-RFC stage), which would be required to implement
Fromfor tuples of arbitrary length. This is a fundamental Rust limitation - even the standard library only implements traits for tuples up to 12 elements.For more information:
Testing
All tests pass successfully:
cargo fmt)cargo clippy)API Summary
Fixes #200
🤖 Generated with Claude Code