| Crates.io | uni_service |
| lib.rs | uni_service |
| version | 0.3.8 |
| created_at | 2025-11-15 12:01:51.816001+00 |
| updated_at | 2026-01-09 03:26:37.88586+00 |
| description | Universal service crate for building cross platform OS services |
| homepage | |
| repository | https://github.com/nu11ptr/uni_service |
| max_upload_size | |
| id | 1934282 |
| size | 43,488 |
A crate for for building cross platform OS services
cargo add uni_service
# or
cargo add uni_service -F tokio
axum example)uni_service_managerunsafeThe hello_service function below is the service, the rest is just boilerplate.
use std::sync::mpsc::Receiver;
use uni_service::{BaseService, run_service};
fn hello_service(shutdown: Receiver<()>, is_service: bool) -> uni_service::Result<()> {
if is_service {
println!("Hello, World! (service mode)");
} else {
println!("Hello, World! (interactive mode)");
}
shutdown.recv()?;
println!("Shutdown signal received. Shutting down...");
Ok(())
}
fn run() -> uni_service::Result<()> {
let service_mode = matches!(std::env::args().nth(1).as_deref(), Some("service"));
let service = BaseService::new_sync("hello_world", hello_service, service_mode);
run_service(service, service_mode)?;
Ok(())
}
fn main() {
if let Err(e) = run() {
eprintln!("Error: {}", e);
std::process::exit(1);
}
}
This is currently beta, however, I am using this myself, so it will become production quality at some point.
Contributions are welcome as long they align with my vision for this crate.