Skip to content

Commit 6e9c3eb

Browse files
konardclaude
andcommitted
Use macro for tuple conversion support up to 12-tuple
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>
1 parent 1fd66fb commit 6e9c3eb

File tree

3 files changed

+879
-128
lines changed

3 files changed

+879
-128
lines changed

rust/links-notation/README.md

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -284,20 +284,45 @@ println!("{}", result);
284284

285285
### Supported Tuple Conversions
286286

287-
The following tuple conversions are supported:
288-
289-
- `(&str, &str)` → Link with ID and one value
290-
- `(String, String)` → Link with ID and one value
291-
- `(&str, LiNo<String>)` → Link with ID and LiNo value
292-
- `(LiNo<String>, LiNo<String>)` → Anonymous link with two values
293-
- `(&str, &str, &str)` → Link with ID and two values
294-
- `(String, String, String)` → Link with ID and two values
295-
- `(&str, LiNo<String>, LiNo<String>)` → Link with ID and two LiNo values
296-
- `(LiNo<String>, LiNo<String>, LiNo<String>)` → Anonymous link with three values
297-
- `(&str, &str, &str, &str)` → Link with ID and three values
298-
- `(String, String, String, String)` → Link with ID and three values
299-
- `(&str, LiNo<String>, LiNo<String>, LiNo<String>)` → Link with ID and three LiNo values
300-
- `(LiNo<String>, LiNo<String>, LiNo<String>, LiNo<String>)` → Anonymous link with four values
287+
Tuple conversions are supported for tuples of size 2 through 12 (following Rust's standard library convention). For each tuple size N, four conversion types are implemented:
288+
289+
1. **All `&str`** - First element becomes ID, rest become values
290+
- `("id", "v1", ...)``(id: v1 ...)`
291+
292+
2. **All `String`** - Same as above but with owned strings
293+
- `(id.to_string(), v1.to_string(), ...)``(id: v1 ...)`
294+
295+
3. **`&str` ID with `LiNo<String>` values** - For nested links
296+
- `("id", lino1, lino2, ...)``(id: <lino1> <lino2> ...)`
297+
298+
4. **All `LiNo<String>`** - Creates anonymous link (no ID)
299+
- `(lino1, lino2, ...)``(<lino1> <lino2> ...)`
300+
301+
#### Examples by Tuple Size
302+
303+
```rust
304+
use links_notation::LiNo;
305+
306+
// 2-tuple
307+
let link: LiNo<String> = ("id", "value").into(); // (id: value)
308+
309+
// 5-tuple
310+
let link: LiNo<String> = ("id", "v1", "v2", "v3", "v4").into(); // (id: v1 v2 v3 v4)
311+
312+
// 8-tuple
313+
let link: LiNo<String> = ("id", "v1", "v2", "v3", "v4", "v5", "v6", "v7").into();
314+
315+
// 12-tuple (maximum)
316+
let link: LiNo<String> = ("id", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11").into();
317+
318+
// Anonymous links from LiNo tuples
319+
let refs: Vec<LiNo<String>> = (1..=6).map(|i| LiNo::Ref(format!("v{}", i))).collect();
320+
let link: LiNo<String> = (refs[0].clone(), refs[1].clone(), refs[2].clone(),
321+
refs[3].clone(), refs[4].clone(), refs[5].clone()).into();
322+
// Result: (v1 v2 v3 v4 v5 v6)
323+
```
324+
325+
This macro-generated implementation reduces code duplication while providing compile-time type safety for all tuple sizes.
301326

302327
## Syntax Examples
303328

0 commit comments

Comments
 (0)