@antprofuse/saddle-skill 0.1.2 → 0.2.0-rc.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,163 +0,0 @@
1
- # Saddle Service 0.1.1 契约
2
-
3
- ## 依赖
4
-
5
- 使用已发布门面包的精确版本:
6
-
7
- ```toml
8
- [package]
9
- edition = "2024"
10
- rust-version = "1.85"
11
-
12
- [dependencies]
13
- saddle-framework = "=0.1.1"
14
- serde = { version = "1", features = ["derive"] }
15
- ```
16
-
17
- Cargo 包名是 `saddle-framework`,Rust 库名是 `saddle`。
18
-
19
- ## 正确的最小模式
20
-
21
- 定义一个零大小的契约类型、可序列化的请求/响应类型,以及独立的处理器:
22
-
23
- ```rust
24
- use saddle::{
25
- CallContext,
26
- service::{Service, ServiceFuture, ServiceHandler},
27
- };
28
- use serde::{Deserialize, Serialize};
29
-
30
- struct Hello;
31
-
32
- #[derive(Deserialize)]
33
- struct HelloRequest {
34
- name: String,
35
- }
36
-
37
- #[derive(Serialize)]
38
- struct HelloResponse {
39
- message: String,
40
- }
41
-
42
- impl Service for Hello {
43
- type Request = HelloRequest;
44
- type Response = HelloResponse;
45
- }
46
-
47
- struct HelloHandler;
48
-
49
- impl ServiceHandler<Hello> for HelloHandler {
50
- fn call<'a>(
51
- &'a self,
52
- _context: &'a CallContext,
53
- request: HelloRequest,
54
- ) -> ServiceFuture<'a, HelloResponse> {
55
- Box::pin(async move {
56
- Ok(HelloResponse {
57
- message: format!("Hello, {}!", request.name),
58
- })
59
- })
60
- }
61
- }
62
- ```
63
-
64
- 只通过 Saddle 注册并暴露 Service:
65
-
66
- ```rust
67
- builder.register::<Hello, _>(
68
- ServiceDescriptor::new("helloworld", "hello", "say_hello"),
69
- HelloHandler,
70
- )?;
71
- builder.expose_json::<Hello>("/hello");
72
- ```
73
-
74
- 使用固定的进程入口:
75
-
76
- ```rust
77
- let database_url = std::env::var("SADDLE_DATABASE_URL")
78
- .expect("SADDLE_DATABASE_URL must be set by deployment configuration");
79
- let config = SaddleConfig::new("helloworld", database_url, listen);
80
-
81
- Saddle::run(config, |builder| {
82
- // Register and expose Services here.
83
- Ok(())
84
- })
85
- ```
86
-
87
- 完整的可编译消费端见 `examples/helloworld`。
88
-
89
- ## 错误模式
90
-
91
- 不要使用未固定版本或兼容版本范围:
92
-
93
- ```toml
94
- # 错误:0.1.x 可能发生不兼容变化。
95
- saddle-framework = "0.1"
96
- ```
97
-
98
- 不要嵌入数据库凭据,也不要提供不安全的回退值:
99
-
100
- ```rust
101
- // 错误:规范示例不能将密钥写入源码。
102
- let database_url = "mysql://user:password@127.0.0.1/application";
103
-
104
- // 错误:缺少部署配置时必须失败,不能静默使用源码中的凭据。
105
- let database_url = std::env::var("SADDLE_DATABASE_URL")
106
- .unwrap_or_else(|_| "mysql://user:password@127.0.0.1/application".into());
107
- ```
108
-
109
- 不要从门面根模块导入 Service trait:
110
-
111
- ```rust
112
- // 0.1.1 中错误:这些类型位于 saddle::service。
113
- use saddle::{Service, ServiceHandler};
114
- ```
115
-
116
- 不要使用 Tokio 或 Axum 实现业务执行入口:
117
-
118
- ```rust
119
- // 错误:业务代码不能拥有运行时或 HTTP 服务器。
120
- #[tokio::main]
121
- async fn main() {}
122
-
123
- tokio::spawn(async move {});
124
- axum::Router::new();
125
- ```
126
-
127
- 不要虚构 0.1.1 未发布的便捷宏或异步 trait 语法:
128
-
129
- ```rust
130
- // 错误:这些不是 0.1.1 中经过验证的公共 API。
131
- #[saddle::service]
132
- async fn hello(...) { ... }
133
-
134
- #[saddle::main]
135
- async fn main() { ... }
136
- ```
137
-
138
- 不要直接创建注册表或数据库:
139
-
140
- ```rust
141
- // 错误:装配和托管 I/O 的创建属于 Saddle。
142
- let registry = saddle::service::ServiceRegistryBuilder::new();
143
- let database = saddle::db::Database::connect(...);
144
- ```
145
-
146
- ## 验证
147
-
148
- 执行:
149
-
150
- ```bash
151
- cargo +1.85.0 check --locked --manifest-path examples/helloworld/Cargo.toml
152
- cargo check --locked --manifest-path examples/helloworld/Cargo.toml
153
- cargo tree --locked --manifest-path examples/helloworld/Cargo.toml \
154
- -p saddle-framework@0.1.1
155
- ```
156
-
157
- 当前已验证结果:
158
-
159
- - Rust 1.85 和当前工具链检查均可针对 crates.io 的 `saddle-framework 0.1.1` 制品编译。
160
- - 依赖树将所有 Saddle 组件解析为 0.1.1。
161
- - 锁文件使用 Cargo 1.85 的不兼容 Rust 版本回退机制解析,因此所有选中包都支持声明的最低 Rust 版本。
162
-
163
- 该示例不能证明运行时已就绪,因为 `SADDLE_DATABASE_URL` 必须指向可访问的数据库,且配置的监听地址必须可用。