First Application
Building Your First Nerve Application
This guide walks you through creating a complete Nerve Framework application from scratch.
Project Setup
Create a new Rust project:
Add dependencies to Cargo.toml:
[package]
name = "my-nerve-app"
version = "0.1.0"
edition = "2021"
[dependencies]
nerve = "0.1.0"
tokio = { version = "1.0", features = ["full"] }
Application Structure
Create a simple sensor monitoring application:
// src/main.rs
use nerve::prelude::*;
use nerve::communication::pubsub::{Publisher, Subscriber};
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("🚀 Starting Nerve Framework Application...");
// Create publisher and subscriber
let mut publisher = Publisher::new();
let mut subscriber = Subscriber::new();
// Subscribe to sensor topics
subscriber.subscribe("sensor.temperature").await?;
subscriber.subscribe("sensor.humidity").await?;
// Start publishing sensor data
tokio::spawn(async move {
let mut counter = 0;
loop {
let temperature = 20.0 + (counter as f32 * 0.1);
let humidity = 50.0 + (counter as f32 * 0.2);
publisher.publish("sensor.temperature", &format!("{}°C", temperature)).await.unwrap();
publisher.publish("sensor.humidity", &format!("{}%", humidity)).await.unwrap();
counter += 1;
tokio::time::sleep(Duration::from_secs(1)).await;
}
});
// Listen for messages
loop {
if let Some(message) = subscriber.receive().await {
println!("📡 Received: {} = {}", message.topic, message.payload);
}
tokio::time::sleep(Duration::from_millis(100)).await;
}
}
Running the Application
Expected output:
🚀 Starting Nerve Framework Application...
📡 Received: sensor.temperature = 20.0°C
📡 Received: sensor.humidity = 50.0%
📡 Received: sensor.temperature = 20.1°C
📡 Received: sensor.humidity = 50.2%
...
Key Concepts Demonstrated
- Publisher/Subscriber Pattern - Core communication model
- Async/Await - Non-blocking operations
- Message Routing - Topic-based message delivery
- Error Handling - Proper error propagation
Next Steps
- Quick Start - Basic setup
- Installation Guide - Detailed installation
- System Overview - Architecture details
- Tutorials - More examples
This is a placeholder file. Full content coming soon.