3个版本
0.1.2 | 2023年11月24日 |
---|---|
0.1.1 | 2022年7月24日 |
0.1.0 | 2022年7月24日 |
#721 in HTTP服务器
11KB
68 行
火箭模块
一个小型包,它添加宏以便方便地在Rocket中组织路由处理程序。虽然它基于Rocket项目构建,但这个包并不直接关联到Rocket项目。
示例
而不是明确指定所有要挂载的路由...
#[get("/")]
pub fn all_articles() {}
#[get("/<_id>")]
pub fn get_article(_id: &str) {}
#[post("/<_id>")]
pub fn post_article(_id: &str) {}
#[route(PATCH, uri = "/<_id>")]
pub fn patch_article(_id: &str) {}
#[launch]
fn rocket() -> _ {
rocket::build()
.mount("/articles", routes![all_articles, get_article, post_article, patch_article])
}
...这个包允许你编写以下代码
#[route_module]
mod articles {
// Same code as above
...
}
#[launch]
fn rocket() -> _ {
rocket::build()
.mount("/articles", module!(articles))
}
安装
要安装rocket_modules
,将其添加到你的Cargo.toml
依赖中。
你还应该添加对rocket
(版本0.5.
或更高版本)的依赖(如果尚未添加)。
[dependencies]
rocket = "0.5.0"
rocket_modules = "0.1.2"
注意:此包的兼容性已在Rocket版本"0.5.0"下进行测试,它可能与之前的版本不兼容。
许可证
此代码是双许可的,可根据需要选择MIT许可证或Apache 2.0许可证。
Apache 2.0
Copyright 2022 Antonius Naumann
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
MIT
MIT License
Copyright (c) 2022 Antonius Naumann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
依赖关系
~16–47MB
~802K SLoC