Skip to content

Commit 26bfad9

Browse files
konardclaude
andcommitted
Rename LinkBuilder to LiNoBuilder for consistent naming
- Rename LinkBuilder struct to LiNoBuilder for naming consistency - Add deprecated type alias for backward compatibility - Update documentation to use LiNoBuilder - Add comprehensive API documentation for alternative approaches: - LiNoBuilder (fluent API for arbitrary-length links) - Vec-based conversions - LiNo::new() static method All 275 tests pass. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c134ebf commit 26bfad9

File tree

3 files changed

+139
-24
lines changed

3 files changed

+139
-24
lines changed

rust/links-notation/README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,117 @@ let link: LiNo<String> = (refs[0].clone(), refs[1].clone(), refs[2].clone(),
324324

325325
This macro-generated implementation reduces code duplication while providing compile-time type safety for all tuple sizes.
326326

327+
## Alternative APIs for Arbitrary-Length Links
328+
329+
Since Rust doesn't support variadic generics, tuples are limited to 12 elements (following Rust's standard library convention). For links with more than 12 values or when the number of values is determined at runtime, use one of these alternative APIs:
330+
331+
### Vec-based Conversions
332+
333+
Convert vectors directly to links:
334+
335+
```rust
336+
use links_notation::LiNo;
337+
338+
// Anonymous link from Vec<&str>
339+
let values: Vec<&str> = vec!["a", "b", "c", "d", "e"];
340+
let link: LiNo<String> = values.into();
341+
println!("{}", link); // (a b c d e)
342+
343+
// Named link from (id, Vec) tuple
344+
let values: Vec<&str> = vec!["v1", "v2", "v3", "v4", "v5"];
345+
let link: LiNo<String> = ("myLink", values).into();
346+
println!("{}", link); // (myLink: v1 v2 v3 v4 v5)
347+
348+
// Large links with more than 12 values
349+
let values: Vec<&str> = (1..=100).map(|_| "val").collect();
350+
let link: LiNo<String> = ("big", values).into();
351+
```
352+
353+
### LiNoBuilder (Fluent API)
354+
355+
Build links using a fluent API for maximum flexibility:
356+
357+
```rust
358+
use links_notation::{LiNo, LiNoBuilder};
359+
360+
// Build a link with chained method calls
361+
let link: LiNo<String> = LiNoBuilder::new()
362+
.id("myLink")
363+
.value("v1")
364+
.value("v2")
365+
.value("v3")
366+
.build();
367+
println!("{}", link); // (myLink: v1 v2 v3)
368+
369+
// Build anonymous link (no ID)
370+
let link: LiNo<String> = LiNoBuilder::new()
371+
.value("a")
372+
.value("b")
373+
.value("c")
374+
.build();
375+
println!("{}", link); // (a b c)
376+
377+
// Mix values and nested LiNo elements
378+
let nested: LiNo<String> = ("inner", "a", "b").into();
379+
let link: LiNo<String> = LiNoBuilder::new()
380+
.id("outer")
381+
.lino(nested)
382+
.value("c")
383+
.build();
384+
println!("{}", link); // (outer: (inner: a b) c)
385+
386+
// Add multiple values at once
387+
let link: LiNo<String> = LiNoBuilder::new()
388+
.id("batch")
389+
.values(vec!["a", "b", "c", "d"])
390+
.build();
391+
println!("{}", link); // (batch: a b c d)
392+
```
393+
394+
### LiNo Static Methods
395+
396+
Create links directly using static methods:
397+
398+
```rust
399+
use links_notation::LiNo;
400+
401+
// Create a named link with LiNo::new()
402+
let values: Vec<LiNo<String>> = vec![
403+
LiNo::Ref("a".to_string()),
404+
LiNo::Ref("b".to_string()),
405+
];
406+
let link = LiNo::new(Some("myId".to_string()), values);
407+
println!("{}", link); // (myId: a b)
408+
409+
// Create an anonymous link with LiNo::anonymous()
410+
let values: Vec<LiNo<String>> = vec![
411+
LiNo::Ref("x".to_string()),
412+
LiNo::Ref("y".to_string()),
413+
LiNo::Ref("z".to_string()),
414+
];
415+
let link = LiNo::anonymous(values);
416+
println!("{}", link); // (x y z)
417+
418+
// Create a reference with LiNo::reference()
419+
let r: LiNo<String> = LiNo::reference("hello".to_string());
420+
println!("{}", r); // hello
421+
422+
// Create links with arbitrary number of values
423+
let values: Vec<LiNo<String>> = (1..=100)
424+
.map(|i| LiNo::Ref(format!("item{}", i)))
425+
.collect();
426+
let link = LiNo::new(Some("hundred".to_string()), values);
427+
```
428+
429+
### API Summary
430+
431+
| API | Max Length | Use Case |
432+
|-----|-----------|----------|
433+
| Tuple conversion | 12 | Most common cases, ergonomic syntax |
434+
| Vec conversion | Unlimited | Runtime-determined or large fixed sets |
435+
| LiNoBuilder | Unlimited | Fluent construction, mixing types |
436+
| LiNo::new() | Unlimited | Direct construction with Vec |
437+
327438
## Syntax Examples
328439

329440
### Doublets (2-tuple)

rust/links-notation/src/lib.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ impl<T> LiNo<T> {
102102
///
103103
/// # Examples
104104
/// ```
105-
/// use links_notation::{LiNo, LinkBuilder};
105+
/// use links_notation::{LiNo, LiNoBuilder};
106106
///
107107
/// // Build a link with many string values
108-
/// let link: LiNo<String> = LinkBuilder::new()
108+
/// let link: LiNo<String> = LiNoBuilder::new()
109109
/// .id("myLink")
110110
/// .value("v1")
111111
/// .value("v2")
@@ -115,28 +115,28 @@ impl<T> LiNo<T> {
115115
///
116116
/// // Build a link with LiNo values
117117
/// let nested: LiNo<String> = ("inner", "a", "b").into();
118-
/// let link: LiNo<String> = LinkBuilder::new()
118+
/// let link: LiNo<String> = LiNoBuilder::new()
119119
/// .id("outer")
120120
/// .lino(nested)
121121
/// .value("c")
122122
/// .build();
123123
/// assert_eq!(format!("{}", link), "(outer: (inner: a b) c)");
124124
///
125125
/// // Build anonymous link
126-
/// let link: LiNo<String> = LinkBuilder::new()
126+
/// let link: LiNo<String> = LiNoBuilder::new()
127127
/// .value("a")
128128
/// .value("b")
129129
/// .build();
130130
/// assert_eq!(format!("{}", link), "(a b)");
131131
/// ```
132132
#[derive(Debug, Clone, Default)]
133-
pub struct LinkBuilder {
133+
pub struct LiNoBuilder {
134134
id: Option<String>,
135135
values: Vec<LiNo<String>>,
136136
}
137137

138-
impl LinkBuilder {
139-
/// Creates a new empty LinkBuilder.
138+
impl LiNoBuilder {
139+
/// Creates a new empty LiNoBuilder.
140140
pub fn new() -> Self {
141141
Self::default()
142142
}
@@ -191,6 +191,10 @@ impl LinkBuilder {
191191
}
192192
}
193193

194+
/// Type alias for backward compatibility (deprecated).
195+
#[deprecated(since = "0.3.0", note = "Use LiNoBuilder instead")]
196+
pub type LinkBuilder = LiNoBuilder;
197+
194198
impl<T: ToString + Clone> LiNo<T> {
195199
/// Format the link using FormatConfig configuration.
196200
///
@@ -1517,7 +1521,7 @@ impl_tuple_from!(12);
15171521
// - https://github.com/rust-lang/rust/issues/10124 (RFC: variadic generics)
15181522
//
15191523
// Alternative approaches for arbitrary-length links:
1520-
// 1. Use the `LinkBuilder` API for fluent construction
1524+
// 1. Use the `LiNoBuilder` API for fluent construction
15211525
// 2. Use `LiNo::new()` or `LiNo::anonymous()` with a `Vec`
15221526
// 3. Use the `From<Vec<_>>` implementations below
15231527

rust/links-notation/tests/tuple_tests.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use links_notation::{format_links, LiNo, LinkBuilder};
1+
use links_notation::{format_links, LiNo, LiNoBuilder};
22

33
#[test]
44
fn test_tuple_to_link_basic() {
@@ -400,13 +400,13 @@ fn test_vec_large_arbitrary_size() {
400400
}
401401

402402
// ============================================================================
403-
// Tests for LinkBuilder API (fluent arbitrary-length construction)
403+
// Tests for LiNoBuilder API (fluent arbitrary-length construction)
404404
// ============================================================================
405405

406406
#[test]
407-
fn test_link_builder_basic() {
407+
fn test_lino_builder_basic() {
408408
// Test basic builder usage
409-
let link: LiNo<String> = LinkBuilder::new()
409+
let link: LiNo<String> = LiNoBuilder::new()
410410
.id("myId")
411411
.value("v1")
412412
.value("v2")
@@ -415,17 +415,17 @@ fn test_link_builder_basic() {
415415
}
416416

417417
#[test]
418-
fn test_link_builder_anonymous() {
418+
fn test_lino_builder_anonymous() {
419419
// Test building anonymous link (no ID)
420-
let link: LiNo<String> = LinkBuilder::new().value("a").value("b").value("c").build();
420+
let link: LiNo<String> = LiNoBuilder::new().value("a").value("b").value("c").build();
421421
assert_eq!(format!("{}", link), "(a b c)");
422422
}
423423

424424
#[test]
425-
fn test_link_builder_with_lino() {
425+
fn test_lino_builder_with_lino() {
426426
// Test builder with LiNo values
427427
let nested: LiNo<String> = ("inner", "x", "y").into();
428-
let link: LiNo<String> = LinkBuilder::new()
428+
let link: LiNo<String> = LiNoBuilder::new()
429429
.id("outer")
430430
.lino(nested)
431431
.value("z")
@@ -434,30 +434,30 @@ fn test_link_builder_with_lino() {
434434
}
435435

436436
#[test]
437-
fn test_link_builder_values_batch() {
437+
fn test_lino_builder_values_batch() {
438438
// Test builder with multiple values at once
439-
let link: LiNo<String> = LinkBuilder::new()
439+
let link: LiNo<String> = LiNoBuilder::new()
440440
.id("batch")
441441
.values(vec!["a", "b", "c", "d"])
442442
.build();
443443
assert_eq!(format!("{}", link), "(batch: a b c d)");
444444
}
445445

446446
#[test]
447-
fn test_link_builder_linos_batch() {
447+
fn test_lino_builder_linos_batch() {
448448
// Test builder with multiple LiNo values at once
449449
let linos: Vec<LiNo<String>> = vec![("child1", "val1").into(), ("child2", "val2").into()];
450-
let link: LiNo<String> = LinkBuilder::new().id("parent").linos(linos).build();
450+
let link: LiNo<String> = LiNoBuilder::new().id("parent").linos(linos).build();
451451
assert_eq!(
452452
format!("{}", link),
453453
"(parent: (child1: val1) (child2: val2))"
454454
);
455455
}
456456

457457
#[test]
458-
fn test_link_builder_large_link() {
458+
fn test_lino_builder_large_link() {
459459
// Test building a link with many values (more than 12)
460-
let mut builder = LinkBuilder::new().id("large");
460+
let mut builder = LiNoBuilder::new().id("large");
461461
for i in 1..=50 {
462462
builder = builder.value(&format!("v{}", i));
463463
}
@@ -469,11 +469,11 @@ fn test_link_builder_large_link() {
469469
}
470470

471471
#[test]
472-
fn test_link_builder_chaining() {
472+
fn test_lino_builder_chaining() {
473473
// Test complex chaining
474474
let nested1: LiNo<String> = ("n1", "a").into();
475475
let nested2: LiNo<String> = ("n2", "b").into();
476-
let link: LiNo<String> = LinkBuilder::new()
476+
let link: LiNo<String> = LiNoBuilder::new()
477477
.id("root")
478478
.value("first")
479479
.lino(nested1)

0 commit comments

Comments
 (0)