ModuLink-rs
Why do I care?
ModuLink-rs is a modular library and minimal framework for agent-based project development in Rust. Whether your project is small or complex, ModuLink-rs is designed to scale with you. Its architecture offloads logic from the developer and bakes it into the structure itself, so you spend less time on boilerplate and more time on your core ideas.
This makes ModuLink-rs especially powerful for AI and agent-based systems: it removes agents from critical decision-making and gives them a designated developer pocket to fill, ensuring clarity, safety, and maintainability. The framework's design lets you build composable, observable, and testable async/sync chains with context-passing, middleware, and branching—so your code stays clean and your logic stays robust.
Composable, observable, and testable async/sync chains for Rust. ModuLink-rs enables modular orchestration of pure functions with context-passing, middleware, and branching—designed for clarity, safety, and real-world scale.
Real-World Example: Modular HTTP Request Pipeline
Suppose you want to build a simple HTTP API endpoint that processes incoming requests, logs them, validates input, and returns a response. ModuLink-rs lets you compose these steps as modular links:
use chain;
use Context;
use HashMap;
// Link: Log the request
+ Send + Sync
// Link: Validate input
+ Send + Sync
// Link: Process and respond
+ Send + Sync
async
This example shows how you can build a modular, testable pipeline for real-world tasks like API handling, logging, and validation. You can easily extend it with more links for authentication, error handling, or business logic.
Quick Start: Real-World Chain Example
Here's how you can build a simple user registration pipeline:
use chain;
use Context;
// Link: Validate user input
+ Send + Sync
// Link: Save user to database (simulated)
+ Send + Sync
async
Shadowing Policy (Ergonomic APIs)
- For all ergonomic usage (
Chain,Link,Context), always use variable shadowing (e.g.,let ctx = ...) instead ofmut. - This prevents accidental mutation and is safer for async/concurrent code. See migration plan for details.
- Advanced/generic APIs may use
mutfor performance, but must document the tradeoff.
Features (with Real-World Examples)
- Ergonomic API: Compose steps like user registration, payment processing, or data validation with minimal boilerplate.
- Context-Driven: Pass data between steps, e.g., user info, payment details, or request metadata.
- Middleware: Add logging, error handling, or authentication as modular links:
+ Send + Sync - Branching: Build conditional flows, e.g., if payment succeeds, send confirmation; else, log error.
- Listeners: Integrate with HTTP endpoints or CLI commands to trigger chains for real-world events.
- Battle-Tested: Use in production for APIs, automation, or agent-based systems.
Real-World Listener Example: HTTP API Endpoint
Here's how you can use ModuLink-rs to create an HTTP endpoint for a contact form:
use Context;
use ;
use Arc;
use Future;
use Pin;
;
// Listener usage
let handler = new;
let listener = HttpListener ;
spawn;
// ...send POST requests to http://127.0.0.1:8089/contact ...
Mut vs. Shadowing (with Real-World Context)
- Shadowing (recommended):
let ctx = ctx.insert; let ctx = ctx.insert; - Mut (rare, for performance):
let mut ctx = new; ctx = ctx.insert; ctx = ctx.insert;
// Advanced usage and generics are omitted for clarity. Focus on practical, relatable examples above.
Documentation
- User Guide: Concepts, patterns, and best practices
- Cheatsheet: Quick reference for ergonomic usage
- Advanced Cheatsheet: Power user and generic patterns
Getting Started
- Add ModuLink-rs to your
Cargo.toml. - See the User Guide for onboarding.
- Explore the Cheatsheet for quick syntax.
- Dive into Advanced Cheatsheet for custom and generic workflows.
TODO
- Finish CI setup for automated testing and publishing
License
ModuLink-rs is licensed under the Apache License, Version 2.0. See LICENSE for details.
For questions, see the docs or open an issue. Happy coding with ModuLink-rs!