ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

simple-starter

simple-starter simple-startersimple-starter是一个模块化的 Rust 应用程序启动框架。它提供一套基于**宏Macros与依赖注入DI**的机制自动管理组件生命周期、依赖关系、配置加载、Web 路由注册与安全校验让你专注于业务逻辑的实现。主要特性自动依赖注入#[component]、#[provider]、#[configuration]三种组件注册方式支持按类型、按名称注入Trait Object 注入#[injectable]#[inject]支持Arcdyn Trait唯一实现、按名称指定实现、VecArcdyn Trait收集全部实现智能生命周期管理自动计算组件依赖拓扑按序 create → init退出时逆序 destroy条件注册condition ComponentCondition::on_missing_trait::dyn T()实现默认实现 用户覆盖分布式路由Web 路由分散定义启动时自动收集聚合无需集中挂载声明式定时任务#[cron_job]直接在函数上定义定时任务分层配置系统application.toml与多环境 Profile 自动合并插件系统assemble/components_ready/finalize三阶段生命周期插件间通过扩展上下文解耦协作事件系统Spring 风格事件发布/监听监听器自动收集、按事件类型分桶分派安全能力编译期资源收集、运行时白名单、用户认证与权限校验模块导航模块说明文档simple-starter-core运行时核心组件模型、依赖注入、插件系统、配置管理、事件系统、任务调度READMEsimple-starter-macro过程宏集合组件注册、依赖注入、路由挂载等声明式注解的代码展开READMEsimple-starter-webWeb 插件Axum 集成、路由自动收集、统一 JSON 响应、监听器扩展READMEsimple-starter-security安全插件编译期资源收集、白名单放行、用户认证与权限校验README模块职责与依赖关系simple-starter-macro纯过程宏不依赖任何模块 ↑ simple-starter-core运行时引擎依赖并重导出核心宏 ↑ simple-starter-webAxum Web 集成依赖 core macro ↑ simple-starter-security安全中间件依赖 core websimple-starter-core框架的核心引擎不依赖任何业务模块。采用 serde 模式依赖并重导出核心宏用户只需依赖 core 即可使用#[component]等宏。simple-starter-macro纯过程宏 crate展开代码通过绝对路径::simple_starter_core::...、::simple_starter_web::...、::simple_starter_security::...引用运行时自身零依赖。注意过程宏 crate 只能导出宏普通类型由各自模块导出。simple-starter-web依赖 core重导出 Web 相关宏。simple-starter-security依赖 core web重导出安全相关宏。用户侧依赖规则使用核心能力组件、DI、事件、定时任务只依赖simple-starter-core使用 Web 路由宏依赖simple-starter-web使用安全宏依赖simple-starter-security均无需直接依赖simple-starter-macro。快速开始一个最小 Web 应用usesimple_starter_core::{component,inject};usesimple_starter_core::Application;usesimple_starter_web::{get_mapping,json_response_wrap,rest_controller,JsonResponse,WebPlugin};usestd::sync::Arc;// 业务组件自动注册、生命周期托管#[component]structGreetingService;// Controller 组件通过 #[inject] 自动装配依赖#[component]structHelloController{#[inject]greeting:ArcGreetingService,}// REST 控制器impl 块级路由注册#[rest_controller(/api)]implHelloController{#[get_mapping(/hello)]asyncfnhello(self)-JsonResponse{json_response_wrap!(messagesuccess,{Ok(hello world.to_string())})}}fnmain(){Application::new().register_plugin(WebPlugin::new()).run();}各模块 README 均内置完整示例组件注入、trait 对象注入、插件协作、Web 路由、安全校验、事件系统可参照实现自己的应用。目录结构simple-starter/ ├── simple-starter-core/ # 运行时核心重点模块见其 README ├── simple-starter-macro/ # 过程宏集合 ├── simple-starter-web/ # Web 插件 ├── simple-starter-security/ # 安全插件 └── README.md # 本文档模块导航
返回列表