cano 0.8.0

High-performance orchestration engine for building resilient, self-healing systems in Rust. Uses Finite State Machines (FSM) for strict, type-safe transitions.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Tasks - Cano Documentation</title>
    <meta name="description" content="Learn how to use Tasks in Cano - simple, flexible processing units for async workflows in Rust.">
    <meta property="og:title" content="Tasks - Cano Documentation">
    <meta property="og:description" content="Simple, flexible processing units for your Cano workflows.">
    <link rel="stylesheet" href="styles.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@500;700&family=Fira+Code&display=swap" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.6.1/mermaid.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-rust.min.js"></script>
    <script src="script.js" defer></script>
    <style>
        /* ── Page-specific styles for task.html ── */

        /* Table of Contents */
        .page-toc {
            background: var(--card-bg);
            border: 1px solid var(--border-color);
            border-radius: 0.75rem;
            padding: 1.5rem 2rem;
            margin-bottom: 3rem;
        }

        .page-toc-title {
            font-size: 0.75rem;
            font-weight: 700;
            letter-spacing: 0.1em;
            text-transform: uppercase;
            color: var(--primary-color);
            margin-bottom: 0.75rem;
        }

        .page-toc ol {
            list-style: none;
            counter-reset: toc-counter;
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
            gap: 0.25rem 2rem;
            padding: 0;
            margin: 0;
        }

        .page-toc li {
            counter-increment: toc-counter;
        }

        .page-toc li a {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            padding: 0.35rem 0;
            color: #94a3b8;
            font-size: 0.925rem;
            font-weight: 500;
            text-decoration: none;
            transition: color 0.2s;
        }

        .page-toc li a::before {
            content: counter(toc-counter, decimal-leading-zero);
            font-size: 0.75rem;
            font-weight: 700;
            color: var(--border-color);
            font-family: 'Fira Code', monospace;
            transition: color 0.2s;
        }

        .page-toc li a:hover {
            color: var(--primary-color);
        }

        .page-toc li a:hover::before {
            color: var(--primary-color);
        }

        /* Section dividers */
        .section-divider {
            border: none;
            height: 1px;
            background: linear-gradient(to right, var(--border-color), transparent);
            margin: 3rem 0 0;
        }

        /* Callout boxes */
        .callout {
            padding: 1.25rem 1.5rem;
            border-radius: 0.75rem;
            margin: 1.5rem 0 2rem;
            border-left: 4px solid;
            font-size: 1rem;
        }

        .callout p {
            margin: 0;
            font-size: 1rem;
            line-height: 1.6;
        }

        .callout-label {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            font-weight: 700;
            font-size: 0.8rem;
            letter-spacing: 0.05em;
            text-transform: uppercase;
            margin-bottom: 0.5rem;
        }

        .callout-info {
            background: rgba(56, 189, 248, 0.08);
            border-color: var(--primary-color);
        }

        .callout-info .callout-label {
            color: var(--primary-color);
        }

        .callout-tip {
            background: rgba(52, 211, 153, 0.08);
            border-color: #34d399;
        }

        .callout-tip .callout-label {
            color: #34d399;
        }

        .callout-warning {
            background: rgba(251, 191, 36, 0.08);
            border-color: #fbbf24;
        }

        .callout-warning .callout-label {
            color: #fbbf24;
        }

        /* Code block labels */
        .code-block {
            position: relative;
            margin: 1.5rem 0;
        }

        .code-block-label {
            display: inline-flex;
            align-items: center;
            gap: 0.4rem;
            background: var(--card-bg);
            border: 1px solid var(--border-color);
            border-bottom: 1px solid var(--code-bg);
            border-radius: 0.5rem 0.5rem 0 0;
            padding: 0.4rem 1rem;
            font-size: 0.78rem;
            font-weight: 600;
            color: #94a3b8;
            letter-spacing: 0.02em;
            position: relative;
            top: 1px;
            z-index: 1;
        }

        .code-block-label .label-icon {
            font-size: 0.85rem;
            opacity: 0.7;
        }

        .code-block pre {
            margin-top: 0 !important;
            border-top-left-radius: 0 !important;
        }

        /* Comparison section */
        .comparison-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 0;
            margin: 2rem 0;
            border-radius: 1rem;
            overflow: hidden;
            border: 1px solid var(--border-color);
        }

        .comparison-col {
            padding: 2rem;
            background: var(--card-bg);
        }

        .comparison-col:first-child {
            border-right: 1px solid var(--border-color);
        }

        .comparison-col h3 {
            margin-top: 0;
            margin-bottom: 0.75rem;
        }

        .comparison-col ul {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        .comparison-col ul li {
            padding: 0.5rem 0;
            color: #94a3b8;
            font-size: 0.95rem;
            display: flex;
            align-items: flex-start;
            gap: 0.5rem;
        }

        .comparison-col ul li::before {
            content: "";
            display: inline-block;
            width: 6px;
            height: 6px;
            border-radius: 50%;
            background: var(--primary-color);
            margin-top: 0.55rem;
            flex-shrink: 0;
        }

        .comparison-col:last-child ul li::before {
            background: var(--secondary-color);
        }

        /* Styled table */
        .styled-table {
            width: 100%;
            border-collapse: separate;
            border-spacing: 0;
            margin: 2rem 0;
            background: var(--card-bg);
            border-radius: 0.75rem;
            overflow: hidden;
            border: 1px solid var(--border-color);
            font-size: 0.95rem;
        }

        .styled-table thead tr {
            background: rgba(255, 255, 255, 0.04);
        }

        .styled-table th {
            padding: 1rem 1.25rem;
            text-align: left;
            font-weight: 600;
            color: #e2e8f0;
            font-size: 0.85rem;
            letter-spacing: 0.03em;
            text-transform: uppercase;
            border-bottom: 1px solid var(--border-color);
        }

        .styled-table td {
            padding: 0.875rem 1.25rem;
            border-top: 1px solid rgba(255, 255, 255, 0.04);
            color: #94a3b8;
        }

        .styled-table tbody tr:first-child td {
            border-top: none;
        }

        .styled-table tbody tr:hover {
            background: rgba(255, 255, 255, 0.02);
        }

        /* Pattern cards */
        .pattern-section {
            margin: 2rem 0;
        }

        .pattern-header {
            display: flex;
            align-items: center;
            gap: 0.75rem;
            margin-bottom: 0.5rem;
        }

        .pattern-number {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 2rem;
            height: 2rem;
            border-radius: 0.5rem;
            background: rgba(56, 189, 248, 0.12);
            color: var(--primary-color);
            font-weight: 700;
            font-size: 0.85rem;
            font-family: 'Fira Code', monospace;
            flex-shrink: 0;
        }

        .pattern-header h3 {
            margin: 0;
        }

        /* Retry card stack improvements */
        .retry-cards .card {
            border-left: 3px solid var(--secondary-color);
        }

        .retry-cards .card:nth-child(1) {
            border-left-color: var(--primary-color);
        }

        .retry-cards .card:nth-child(2) {
            border-left-color: var(--secondary-color);
        }

        .retry-cards .card:nth-child(3) {
            border-left-color: #34d399;
        }

        /* Responsive adjustments */
        @media (max-width: 768px) {
            .page-toc ol {
                grid-template-columns: 1fr;
            }

            .page-toc {
                padding: 1.25rem 1.25rem;
            }

            .comparison-grid {
                grid-template-columns: 1fr;
            }

            .comparison-col:first-child {
                border-right: none;
                border-bottom: 1px solid var(--border-color);
            }

            .comparison-col {
                padding: 1.25rem;
            }

            .callout {
                padding: 1rem 1.25rem;
            }

            .styled-table {
                font-size: 0.85rem;
                display: block;
                overflow-x: auto;
                -webkit-overflow-scrolling: touch;
            }

            .styled-table th,
            .styled-table td {
                padding: 0.625rem 0.75rem;
                white-space: nowrap;
            }
        }

        @media (max-width: 480px) {
            .styled-table th,
            .styled-table td {
                padding: 0.5rem 0.625rem;
                font-size: 0.8rem;
            }
        }
    </style>
</head>
<body>
    <button id="menu-toggle" class="menu-toggle" aria-label="Toggle navigation" aria-expanded="false">&#9776;</button>
    <div class="sidebar-overlay"></div>

    <nav class="sidebar" role="navigation" aria-label="Main navigation">
        <a href="index.html" class="logo">
            <img src="logo.png" alt="" style="height: 24px; vertical-align: middle; margin-right: 8px;">
            Cano
        </a>
        <ul class="nav-links">
            <li><a href="index.html">Home</a></li>
            <li><a href="task.html" class="active">Tasks</a></li>
            <li><a href="nodes.html">Nodes</a></li>
            <li><a href="workflows.html">Workflows</a></li>
            <li><a href="store.html">Store</a></li>
            <li><a href="scheduler.html">Scheduler</a></li>
            <li><a href="tracing.html">Tracing</a></li>
        </ul>
        <div class="sidebar-footer">
            <span class="version-badge">v0.8.0</span>
            <div class="sidebar-links">
                <a href="https://github.com/nassor/cano" title="GitHub Repository" aria-label="GitHub">GitHub</a>
                <a href="https://crates.io/crates/cano" title="Crates.io" aria-label="Crates.io">Crates.io</a>
                <a href="https://docs.rs/cano" title="API Documentation" aria-label="API Docs">Docs.rs</a>
            </div>
        </div>
    </nav>

    <main class="main-content">
        <h1>Tasks</h1>
        <p class="subtitle">Simple, flexible processing units for your workflows.</p>

        <p>
            A <code>Task</code> provides a simplified interface with a single <code>run</code> method.
            Use tasks when you want simplicity and direct control over the execution logic.
            Tasks are the fundamental building blocks of Cano workflows.
        </p>

        <div class="callout callout-info">
            <div class="callout-label">Key concept</div>
            <p>
                A Task is the simplest way to define workflow logic in Cano. Implement a single <code>run()</code> method,
                and you have a fully functional processing unit. For more structured operations, see <a href="nodes.html">Nodes</a>.
            </p>
        </div>

        <!-- Table of Contents -->
        <nav class="page-toc" aria-label="Table of contents">
            <div class="page-toc-title">On this page</div>
            <ol>
                <li><a href="#implementing">Implementing a Task</a></li>
                <li><a href="#closures">Closure Tasks</a></li>
                <li><a href="#config-retries">Configuration &amp; Retries</a></li>
                <li><a href="#patterns">Real-World Task Patterns</a></li>
                <li><a href="#task-vs-node">Task vs Node</a></li>
                <li><a href="#when-to-use">When to Use Tasks vs Nodes</a></li>
            </ol>
        </nav>

        <!-- Section: Implementing a Task -->
        <hr class="section-divider">
        <h2 id="implementing">Implementing a Task</h2>
        <p>To create a task, implement the <code>Task</code> trait for your struct. The trait requires a <code>run</code> method and an optional <code>config</code> method.</p>

        <div class="code-block">
            <span class="code-block-label"><span class="label-icon">&#9998;</span> Implementing Task trait</span>
            <pre><code class="language-rust">use async_trait::async_trait;
use cano::prelude::*;
use rand::RngExt;

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
enum Action { Generate, Count, Complete }

struct GeneratorTask;

#[async_trait]
impl Task<Action> for GeneratorTask {
    // Optional: Configure retries
    fn config(&self) -> TaskConfig {
        TaskConfig::default().with_fixed_retry(3, std::time::Duration::from_secs(1))
    }

    async fn run(&self, store: &MemoryStore) -> Result<TaskResult<Action>, CanoError> {
        println!("🎲 GeneratorTask: Creating random numbers...");

        // 1. Perform logic
        let mut rng = rand::rng();
        let numbers: Vec<u32> = (0..10).map(|_| rng.random_range(1..=100)).collect();

        // 2. Store results
        store.put("numbers", numbers)?;
        println!("✅ Stored numbers");

        // 3. Return next state
        Ok(TaskResult::Single(Action::Count))
    }
}</code></pre>
        </div>

        <!-- Section: Closure Tasks -->
        <hr class="section-divider">
        <h2 id="closures">Closure Tasks</h2>
        <p>For very simple logic, you can register a closure directly as a task without defining a struct.</p>

        <div class="code-block">
            <span class="code-block-label"><span class="label-icon">&#955;</span> Closure as a Task</span>
            <pre><code class="language-rust">workflow.register(Action::Count, |store: &MemoryStore| async move {
    let numbers: Vec<u32> = store.get("numbers")?;
    println!("Count: {}", numbers.len());
    Ok(TaskResult::Single(Action::Complete))
});</code></pre>
        </div>

        <div class="callout callout-tip">
            <div class="callout-label">Tip</div>
            <p>Closures are great for prototyping and simple logic. When your closure starts growing beyond a few lines, consider refactoring into a named struct with the <code>Task</code> trait.</p>
        </div>

        <!-- Section: Configuration & Retries -->
        <hr class="section-divider">
        <h2 id="config-retries">Configuration &amp; Retries</h2>
        <p>
            Tasks can be configured with retry strategies to handle transient failures.
            The <code>TaskConfig</code> struct allows you to specify the retry behavior.
        </p>

        <h3>Retry Strategy Examples</h3>
        <div class="mermaid">
            sequenceDiagram
                participant W as Workflow
                participant T as Task
                W->>T: Execute
                T-->>W: Fail
                Note over W: Wait (backoff)
                W->>T: Retry 1
                T-->>W: Fail
                Note over W: Wait (longer)
                W->>T: Retry 2
                T-->>W: Success ✓
        </div>

        <div class="card-stack retry-cards">
            <div class="card">
                <h3>Fixed Retry</h3>
                <p>Retry a fixed number of times with a constant delay between attempts.</p>
                <div class="code-block">
                    <span class="code-block-label">Fixed retry config</span>
                    <pre><code class="language-rust">TaskConfig::default()
    .with_fixed_retry(3, Duration::from_secs(1))</code></pre>
                </div>
            </div>
            <div class="card">
                <h3>Exponential Backoff</h3>
                <p>Retry with exponentially increasing delays, useful for rate-limited APIs.</p>
                <div class="code-block">
                    <span class="code-block-label">Exponential backoff config</span>
                    <pre><code class="language-rust">TaskConfig::default()
    .with_exponential_retry(5)</code></pre>
                </div>
            </div>
            <div class="card">
                <h3>Minimal Config</h3>
                <p>Fast execution with minimal retry overhead for reliable operations.</p>
                <div class="code-block">
                    <span class="code-block-label">Minimal config</span>
                    <pre><code class="language-rust">TaskConfig::minimal()</code></pre>
                </div>
            </div>
        </div>

        <h3>Real-World Example: API Client with Retry</h3>

        <div class="code-block">
            <span class="code-block-label"><span class="label-icon">&#127760;</span> API client with exponential backoff</span>
            <pre><code class="language-rust">use cano::prelude::*;
use async_trait::async_trait;

#[derive(Clone)]
struct ApiClientTask {
    endpoint: String,
}

#[async_trait]
impl Task<State> for ApiClientTask {
    fn config(&self) -> TaskConfig {
        // Exponential backoff for API rate limiting
        TaskConfig::default()
            .with_exponential_retry(5)
    }

    async fn run(&self, store: &MemoryStore) -> Result<TaskResult<State>, CanoError> {
        println!("📡 Calling API: {}", self.endpoint);

        // Simulate API call that might fail
        let response = reqwest::get(&self.endpoint)
            .await
            .map_err(|e| CanoError::task_execution(e.to_string()))?;

        let data = response.text().await
            .map_err(|e| CanoError::task_execution(e.to_string()))?;

        store.put("api_response", data)?;
        println!("✅ API call successful");

        Ok(TaskResult::Single(State::Complete))
    }
}</code></pre>
        </div>

        <!-- Section: Real-World Patterns -->
        <hr class="section-divider">
        <h2 id="patterns">Real-World Task Patterns</h2>
        <p>Tasks excel at various workflow scenarios. Here are proven patterns from production use.</p>

        <section class="pattern-section">
            <div class="pattern-header">
                <span class="pattern-number">1</span>
                <h3>Data Transformation Task</h3>
            </div>
            <p>Simple, direct data processing without complex setup.</p>
            <div class="code-block">
                <span class="code-block-label">Data transformation</span>
                <pre><code class="language-rust">#[derive(Clone)]
struct DataTransformer;

#[async_trait]
impl Task<State> for DataTransformer {
    async fn run(&self, store: &MemoryStore) -> Result<TaskResult<State>, CanoError> {
        let raw_data: Vec<i32> = store.get("raw_data")?;

        // Transform: filter and multiply
        let processed: Vec<i32> = raw_data
            .into_iter()
            .filter(|&x| x > 0)
            .map(|x| x * 2)
            .collect();

        store.put("processed_data", processed)?;
        Ok(TaskResult::Single(State::Complete))
    }
}</code></pre>
            </div>
        </section>

        <section class="pattern-section">
            <div class="pattern-header">
                <span class="pattern-number">2</span>
                <h3>Validation Task</h3>
            </div>
            <p>Quick validation logic with multiple outcomes.</p>
            <div class="code-block">
                <span class="code-block-label">Validation with branching</span>
                <pre><code class="language-rust">#[derive(Clone)]
struct ValidatorTask;

#[async_trait]
impl Task<State> for ValidatorTask {
    async fn run(&self, store: &MemoryStore) -> Result<TaskResult<State>, CanoError> {
        let data: Vec<f64> = store.get("processed_data")?;

        let mut errors = Vec::new();

        if data.is_empty() {
            errors.push("Data is empty");
        }

        if data.iter().any(|&x| x.is_nan()) {
            errors.push("Contains NaN values");
        }

        store.put("validation_errors", errors.clone())?;

        if errors.is_empty() {
            Ok(TaskResult::Single(State::Process))
        } else {
            Ok(TaskResult::Single(State::ValidationFailed))
        }
    }
}</code></pre>
            </div>
        </section>

        <section class="pattern-section">
            <div class="pattern-header">
                <span class="pattern-number">3</span>
                <h3>Conditional Routing Task</h3>
            </div>
            <p>Dynamic workflow routing based on runtime conditions.</p>
            <div class="code-block">
                <span class="code-block-label">Dynamic routing with match</span>
                <pre><code class="language-rust">#[derive(Clone)]
struct RoutingTask;

#[async_trait]
impl Task<State> for RoutingTask {
    async fn run(&self, store: &MemoryStore) -> Result<TaskResult<State>, CanoError> {
        let item_count: usize = store.get("item_count")?;
        let priority: String = store.get("priority")?;

        // Dynamic routing based on conditions
        let next_state = match (item_count, priority.as_str()) {
            (n, "high") if n > 100 => State::ParallelProcess,
            (n, "high") if n > 0 => State::FastTrack,
            (n, _) if n > 50 => State::BatchProcess,
            (n, _) if n > 0 => State::SimpleProcess,
            _ => State::Skip,
        };

        println!("Routing to: {:?}", next_state);
        Ok(TaskResult::Single(next_state))
    }
}</code></pre>
            </div>
        </section>

        <section class="pattern-section">
            <div class="pattern-header">
                <span class="pattern-number">4</span>
                <h3>Aggregation Task</h3>
            </div>
            <p>Collect and combine results from previous steps.</p>
            <div class="code-block">
                <span class="code-block-label">Aggregating parallel results</span>
                <pre><code class="language-rust">#[derive(Clone)]
struct AggregatorTask;

#[async_trait]
impl Task<State> for AggregatorTask {
    async fn run(&self, store: &MemoryStore) -> Result<TaskResult<State>, CanoError> {
        println!("Aggregating results...");

        let mut total = 0;
        let mut count = 0;

        // Collect results from parallel tasks
        for i in 1..=3 {
            if let Ok(result) = store.get::<i32>(&format!("result_{}", i)) {
                total += result;
                count += 1;
            }
        }

        store.put("total", total)?;
        store.put("count", count)?;

        println!("Aggregated {} results, total: {}", count, total);
        Ok(TaskResult::Single(State::Complete))
    }
}</code></pre>
            </div>
        </section>

        <!-- Section: Task vs Node -->
        <hr class="section-divider">
        <h2 id="task-vs-node">Task vs Node</h2>
        <p>
            Cano supports both <code>Task</code> and <code>Node</code> interfaces. Every Node automatically implements Task, so they can be mixed in the same workflow.
        </p>

        <div class="comparison-grid">
            <div class="comparison-col">
                <h3>Task</h3>
                <p><strong>Best for:</strong> Simple logic, quick prototyping, functional style.</p>
                <ul>
                    <li>Single <code>run()</code> method</li>
                    <li>Direct control over flow</li>
                    <li>Can be a closure</li>
                </ul>
            </div>
            <div class="comparison-col">
                <h3>Node</h3>
                <p><strong>Best for:</strong> Complex operations, robust error handling, structured data flow.</p>
                <ul>
                    <li>3 Phases: <code>prep</code>, <code>exec</code>, <code>post</code></li>
                    <li>Full-pipeline retry: <code>prep</code> &rarr; <code>exec</code> &rarr; <code>post</code> restarts on failure</li>
                    <li>Separation of concerns (IO vs Compute)</li>
                </ul>
            </div>
        </div>

        <div class="code-block">
            <span class="code-block-label"><span class="label-icon">&#128260;</span> Mixing Tasks and Nodes</span>
            <pre><code class="language-rust">// Mixing Tasks and Nodes in one workflow
let workflow = Workflow::new(store.clone())
    .register(State::Init, SimpleTask)           // Task
    .register(State::Process, ComplexNode::new()) // Node
    .register(State::Finish, |_: &MemoryStore| async { // Closure Task
        Ok(TaskResult::Single(State::Done))
    });</code></pre>
        </div>

        <!-- Section: When to Use -->
        <hr class="section-divider">
        <h2 id="when-to-use">When to Use Tasks vs Nodes?</h2>
        <p>Choose the right abstraction for your use case:</p>

        <table class="styled-table">
            <thead>
                <tr>
                    <th>Scenario</th>
                    <th>Use Task</th>
                    <th>Use Node</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Data transformation</td>
                    <td>Simple transform</td>
                    <td>Complex with validation</td>
                </tr>
                <tr>
                    <td>API calls</td>
                    <td>Simple requests</td>
                    <td>With auth &amp; retry logic</td>
                </tr>
                <tr>
                    <td>Validation</td>
                    <td>Quick checks</td>
                    <td>Usually overkill</td>
                </tr>
                <tr>
                    <td>File operations</td>
                    <td>For simple cases</td>
                    <td>Load, process, save pattern</td>
                </tr>
                <tr>
                    <td>Prototyping</td>
                    <td>Fastest iteration</td>
                    <td>More structure</td>
                </tr>
                <tr>
                    <td>Production systems</td>
                    <td>When simple is sufficient</td>
                    <td>For robust operations</td>
                </tr>
            </tbody>
        </table>
    </main>
</body>
</html>