路由
2024/12/30小于 1 分钟hyperlanewebrustconfigroute
提示
hyperlane 框架使用 route 进行路由注册,参数是路由路径模式, 框架支持动态路由,更多路由详细使用请参考官方文档。
原生写法
struct Route;
impl ServerHook for Route {
async fn new(_: &mut Stream, _: &mut Context) -> Self {
Self
}
async fn handle(self, stream: &mut Stream, ctx: &mut Context) -> Status {
Status::Continue
}
}
let mut server: Server = Server::default();
server.route::<Route>("/route");属性宏写法
use hyperlane::*;
use hyperlane_macros::*;
#[route("/route")]
struct Route;
impl ServerHook for Route {
async fn new(_: &mut Stream, _: &mut Context) -> Self {
Self
}
async fn handle(self, stream: &mut Stream, ctx: &mut Context) -> Status {
Status::Continue
}
}