Expand description
§Maestro
maestro is a unified, high-performance framework for creating, supervising, and managing
asynchronous network services in Rust.
This library’s purpose is to simplify the creation, supervision, and coordination of network-based services. It provides a structured, asynchronous foundation for managing TCP and UDP protocols, handling service lifecycles, and ensuring robust, scalable operation. By abstracting complex networking patterns, it allows developers to focus on service logic while the library handles concurrency, fault tolerance, and graceful shutdown.
§Example
use maestro_rs::{NetworkInterface, Result, Supervisor, TcpHandler, UdpHandler, async_trait};
use std::{net::SocketAddr, str::FromStr, sync::Arc};
use tokio::{io::{AsyncReadExt, AsyncWriteExt}, net::{TcpStream, UdpSocket}};
use tracing::{error, info};
struct MyTcpService;
#[async_trait]
impl TcpHandler for MyTcpService {
fn name(&self) -> &'static str {
"MyTcpService"
}
fn port(&self) -> u16 {
8080
}
async fn on_connection(&self, mut stream: TcpStream, peer: &SocketAddr) {
unimplemented!()
}
}
struct MyUdpService;
#[async_trait]
impl UdpHandler for MyUdpService {
fn name(&self) -> &'static str {
"MyUdpService"
}
fn port(&self) -> u16 {
5353
}
async fn on_packet(&self, data: &[u8], socket: Arc<UdpSocket>, peer: &SocketAddr) {
unimplemented!()
}
}
#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.init();
let iface = NetworkInterface::from_str("lo")?;
let mut supervisor = Supervisor::new(iface);
supervisor.add(MyUdpService);
supervisor.add(MyTcpService);
supervisor.run().await?;
Ok(())
}Structs§
- Network
Interface - Represents a local network interface and its associated addresses.
- Restart
Policy - Defines how a service should be restarted upon failure.
- Supervisor
- The supervisor orchestrates the lifecycle of multiple services.
- Tcp
- Marker type for TCP service registration.
- Udp
- Marker type for UDP service registration.
Enums§
- Bind
Mode - Strategies for binding sockets to network interfaces.
- Error
- Centralized error type for Maestro.
Traits§
- TcpHandler
- Defines the behavior of a TCP service.
- UdpHandler
- Defines the behavior of a UDP service.
Type Aliases§
- Result
- Helper alias for
Result<T, maestro_rs::Error>