From ce0f916decd5fb10986540daae384b4a804246df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=90=91=E5=A4=9C?= Date: Sat, 6 Apr 2024 21:31:34 +0800 Subject: [PATCH] test: refactor tests for newer version of oblivion --- oblivion-codegen/src/lib.rs | 17 ++++------------ src/lib.rs | 39 ++++++++++++++++--------------------- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/oblivion-codegen/src/lib.rs b/oblivion-codegen/src/lib.rs index 16765b3..8bbec21 100644 --- a/oblivion-codegen/src/lib.rs +++ b/oblivion-codegen/src/lib.rs @@ -7,28 +7,19 @@ use syn::{parse_macro_input, ItemFn}; /// ## Oblivion 业务函数宏 /// -/// 请在使用该属性宏的`.rs`文件中加入: -/// -/// ```rust -/// use futures::future::{BoxFuture, FutureExt}; -/// ``` -/// -/// 然后再引入并使用它。 -/// /// 这是一个示例: /// /// ```rust -/// use futures::future::{BoxFuture, FutureExt}; /// use oblivion::oblivion_codegen::async_route; /// use oblivion::utils::parser::OblivionRequest; -/// use oblivion::models::render::BaseResponse; +/// use oblivion::models::render::{BaseResponse, Response}; /// /// #[async_route] -/// fn welcome(mut req: OblivionRequest) -> BaseResponse { -/// BaseResponse::TextResponse( +/// fn welcome(mut req: OblivionRequest) -> Response { +/// Ok(BaseResponse::TextResponse( /// format!("欢迎进入信息绝对安全区, 来自[{}]的朋友", req.get_ip()), /// 200, -/// ) +/// )) /// } /// ``` #[proc_macro_attribute] diff --git a/src/lib.rs b/src/lib.rs index 2a34f3d..a6d73c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,19 +40,18 @@ pub mod models { /// Routing can be simply implemented using routing macros: /// /// ```rust -/// use futures::future::{BoxFuture, FutureExt}; /// use oblivion::path_route; /// use oblivion::utils::parser::OblivionRequest; -/// use oblivion::models::render::BaseResponse; +/// use oblivion::models::render::{BaseResponse, Response}; /// use oblivion_codegen::async_route; /// use oblivion::models::router::Router; /// /// #[async_route] -/// fn welcome(mut req: OblivionRequest) -> BaseResponse { -/// BaseResponse::TextResponse( +/// fn welcome(mut req: OblivionRequest) -> Response { +/// Ok(BaseResponse::TextResponse( /// format!("欢迎进入信息绝对安全区, 来自[{}]的朋友", req.get_ip()), /// 200, -/// ) +/// )) /// } /// /// let mut router = Router::new(); @@ -63,9 +62,8 @@ pub mod models { #[macro_export] macro_rules! path_route { ($router:expr, $path:expr => $handler:ident) => {{ - let mut router = $router; let route = $crate::models::router::Route::new($handler); - router.regist( + $router.regist( $crate::models::router::RoutePath::new($path, $crate::models::router::RouteType::Path), route, ); @@ -77,32 +75,30 @@ macro_rules! path_route { /// Starting routes can be simply implemented using the start route macro: /// /// ```rust -/// use futures::future::{BoxFuture, FutureExt}; /// use oblivion::startswith_route; /// use oblivion::utils::parser::OblivionRequest; -/// use oblivion::models::render::BaseResponse; +/// use oblivion::models::render::{BaseResponse, Response}; /// use oblivion_codegen::async_route; /// use oblivion::models::router::Router; /// /// #[async_route] -/// fn welcome(mut req: OblivionRequest) -> BaseResponse { -/// BaseResponse::TextResponse( +/// fn welcome(mut req: OblivionRequest) -> Response { +/// Ok(BaseResponse::TextResponse( /// format!("欢迎进入信息绝对安全区, 来自[{}]的朋友", req.get_ip()), /// 200, -/// ) +/// )) /// } /// /// let mut router = Router::new(); -/// startswith_route!(&mut router, "/welcome" => welcome); +/// startswith_route!(router, "/welcome" => welcome); /// ``` /// /// The above route will direct all Oblivion Location Path String starting with `/welcome`. #[macro_export] macro_rules! startswith_route { ($router:expr, $path:expr => $handler:ident) => {{ - let mut router = $router; let route = $crate::models::router::Route::new($handler); - router.regist( + $router.regist( $crate::models::router::RoutePath::new( $path, $crate::models::router::RouteType::StartswithPath, @@ -120,20 +116,20 @@ macro_rules! startswith_route { /// use futures::future::{BoxFuture, FutureExt}; /// use oblivion::regex_route; /// use oblivion::utils::parser::OblivionRequest; -/// use oblivion::models::render::BaseResponse; +/// use oblivion::models::render::{BaseResponse, Response}; /// use oblivion_codegen::async_route; /// use oblivion::models::router::Router; /// /// #[async_route] -/// fn welcome(mut req: OblivionRequest) -> BaseResponse { -/// BaseResponse::TextResponse( +/// fn welcome(mut req: OblivionRequest) -> Response { +/// Ok(BaseResponse::TextResponse( /// format!("欢迎进入信息绝对安全区, 来自[{}]的朋友", req.get_ip()), /// 200, -/// ) +/// )) /// } /// /// let mut router = Router::new(); -/// regex_route!(&mut router, r"^/welcome/.*" => welcome); +/// regex_route!(router, r"^/welcome/.*" => welcome); /// ``` /// /// The above route will direct all Oblivion Location Path String starting with `/welcome/`. @@ -142,9 +138,8 @@ macro_rules! startswith_route { #[macro_export] macro_rules! regex_route { ($router:expr, $path:expr => $handler:ident) => {{ - let mut router = $router; let route = $crate::models::router::Route::new($handler); - router.regist( + $router.regist( $crate::models::router::RoutePath::new( $path, $crate::models::router::RouteType::RegexPath,