2 个版本
0.1.1 | 2024 年 6 月 5 日 |
---|---|
0.1.0 | 2024 年 6 月 5 日 |
#437 in Unix APIs
5KB
54 代码行
rs-svc
在 Linux 上运行的 Rust 服务包装器
示例
见 examples
use rs_svc::svc::service::Service;
struct MyService;
impl Service for MyService {
fn init(&self) -> anyhow::Result<()> {
println!("init");
Ok(())
}
// must be non-blocking
fn start(&self) -> anyhow::Result<()> {
std::thread::spawn(move || {
println!("start")
});
Ok(())
}
fn stop(&self) -> anyhow::Result<()> {
print!("stop");
Ok(())
}
}
fn main() {
let my_svc = MyService;
rs_svc::svc::service::run(&my_svc).unwrap()
}
lib.rs
:
运行在 Linux 上的 Rust 服务包装器库
示例
use rs_svc::svc::service::Service;
struct MyService;
impl Service for MyService {
fn init(&self) -> anyhow::Result<()> {
println!("init");
Ok(())
}
// must be non-blocking
fn start(&self) -> anyhow::Result<()> {
std::thread::spawn(move || {
println!("start")
});
Ok(())
}
fn stop(&self) -> anyhow::Result<()> {
print!("stop");
Ok(())
}
}
fn main() {
let my_svc = MyService;
rs_svc::svc::service::run(&my_svc).unwrap()
}
依赖项
~330KB