Skip to content

Commit e2cbef9

Browse files
eyre フレーバーと tracing フレーバーを追加 (#113)
* feat: eyre & tracing の flavor を追加 * feat: eyre flavor と tracing flavor のテストを追加 * feat: flavor-eyre のドキュメント説明を追加 * feat: flavor-tracing のドキュメント説明を追加 * fix: cargo sort 忘れ
1 parent 5d6d9bf commit e2cbef9

File tree

25 files changed

+1445
-23
lines changed

25 files changed

+1445
-23
lines changed

Cargo.lock

Lines changed: 152 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/ja/hooq-mdbook-ja/src/reference/features.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ hooqクレートにもいくつかのfeaturesが存在します。本ページ
66
|:---------|:--------:|:----|
77
| default | o | デフォルトfeature。 `consume-question` 以外を含む |
88
| full | x | すべてのfeatureを含むfeature |
9-
| log | o | logフレーバーを提供するfeature |
109
| anyhow | o | anyhowフレーバーを提供するfeature |
10+
| eyre | o | eyreフレーバーを提供するfeature |
11+
| log | o | logフレーバーを提供するfeature |
12+
| tracing | o | tracingフレーバーを提供するfeature |
1113
| consume-question | x | `!` (Exclamation Mark)による `?` 演算子 (Question Operator) の削除を行えるようになるfeature |
1214

1315
`consume-question` のみがデフォルトから外れた機能であり、フレーバーを提供するためのfeatureはデフォルトで含まれています。

docs/ja/hooq-mdbook-ja/src/reference/flavors.md

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
| [default](#default) | - | 何も指定しない場合に設定されるフレーバー。hooq.tomlで上書き可 |
1010
| [empty](#empty) | - | 全く何もフックしない場合に用いるフレーバー。上書きは不可 |
1111
| [hook](#hook) | - | [`hooq::HooqMeta`](https://docs.rs/hooq/latest/hooq/struct.HooqMeta.html) を引数に取る `hook` メソッドを挿入するフレーバー。ユーザー定義のトレイト経由での利用を想定。上書き可 |
12-
| [log](#log) | log | [`::log::error!`](https://docs.rs/log/latest/log/macro.error.html) を呼び出す `inspect_err` メソッドを挿入するフレーバー。上書き可 |
1312
| [anyhow](#anyhow) | anyhow | [`with_context`](https://docs.rs/anyhow/latest/anyhow/trait.Context.html#tymethod.with_context) メソッドを挿入するフレーバー。上書き可 |
14-
| [eyre](#eyre--color-eyre) | eyre | (WIP) |
15-
| [tracing](#tracing) | tracing | (WIP) |
13+
| [eyre](#eyre) | eyre | [`wrap_err_with`](https://docs.rs/eyre/latest/eyre/trait.WrapErr.html#tymethod.wrap_err_with) メソッドを挿入するフレーバー。上書き可 |
14+
| [log](#log) | log | [`::log::error!`](https://docs.rs/log/latest/log/macro.error.html) を呼び出す `inspect_err` メソッドを挿入するフレーバー。上書き可 |
15+
| [tracing](#tracing) | tracing | [`::tracing::error!`](https://docs.rs/tracing/latest/tracing/macro.error.html) を呼び出す `inspect_err` メソッドを挿入するフレーバー。上書き可 |
1616

1717
一応feature名を記載しましたが、フレーバーに関係するfeatureはdefault featureに含まれているので明示的にCargo.tomlの `features` に含める必要はありません。
1818

@@ -126,6 +126,59 @@ hookフレーバーの設定は次の通りです。(コメント部分は気に
126126
{{#rustdoc_include ../../../../../mdbook-source-code/flavor-hook/src/main.expanded.rs:37:53}}
127127
```
128128

129+
## anyhow
130+
131+
> `anyhow` feature が必要ですが、defaultに含まれています。
132+
133+
[anyhowクレート](https://docs.rs/anyhow/latest/anyhow/) と共に使うことを想定したフレーバーです。
134+
135+
次の設定になっています。
136+
137+
```rust
138+
{{#rustdoc_include ../../../../../hooq-macros/src/impls/flavor/presets/anyhow.rs:7:28}}
139+
```
140+
141+
[`.with_context(...)`](https://docs.rs/anyhow/latest/anyhow/trait.Context.html#tymethod.with_context) メソッドを利用するために、 `anyhow::Context` トレイトをuseしています。
142+
143+
144+
使用例:
145+
146+
```rust
147+
{{#rustdoc_include ../../../../../mdbook-source-code/flavor-anyhow/src/main.rs}}
148+
```
149+
150+
実行結果:
151+
152+
```bash
153+
{{#include ../../../../../mdbook-source-code/flavor-anyhow/tests/snapshots/test__flavor-anyhow.snap:8:13}}
154+
```
155+
156+
## eyre
157+
158+
> `eyre` feature が必要ですが、defaultに含まれています。
159+
160+
[eyreクレート](https://docs.rs/eyre/latest/eyre/) と共に使うことを想定したフレーバーです。anyhowとはuseしているトレイト、呼び出しているメソッドが異なるだけでほぼ同じです。
161+
162+
次の設定になっています。
163+
164+
```rust
165+
{{#rustdoc_include ../../../../../hooq-macros/src/impls/flavor/presets/eyre.rs:7:28}}
166+
```
167+
168+
[`.wrap_err_with(...)`](https://docs.rs/eyre/latest/eyre/trait.WrapErr.html#tymethod.wrap_err_with) メソッドを利用するために、 `eyre::WrapErr` トレイトをuseしています。
169+
170+
使用例:
171+
172+
```rust
173+
{{#rustdoc_include ../../../../../mdbook-source-code/flavor-eyre/src/main.rs}}
174+
```
175+
176+
実行結果:
177+
178+
```bash
179+
{{#include ../../../../../mdbook-source-code/flavor-eyre/tests/snapshots/test__flavor-eyre.snap:8:22}}
180+
```
181+
129182
## log
130183

131184
> `log` feature が必要ですが、defaultに含まれています。
@@ -150,37 +203,28 @@ hookフレーバーの設定は次の通りです。(コメント部分は気に
150203
{{#include ../../../../../mdbook-source-code/flavor-log/tests/snapshots/test__flavor-log.snap:8:11}}
151204
```
152205

153-
## anyhow
206+
## tracing
154207

155-
> `anyhow` feature が必要ですが、defaultに含まれています。
208+
> `tracing` feature が必要ですが、defaultに含まれています。
156209
157-
[anyhowクレート](https://docs.rs/anyhow/latest/anyhow/) と共に使うことを想定したフレーバーです。
210+
[tracingクレート](https://docs.rs/tracing/latest/tracing/) と共に使うことを想定したフレーバーです。
158211

159212
次の設定になっています。
160213

161214
```rust
162-
{{#rustdoc_include ../../../../../hooq-macros/src/impls/flavor/presets/anyhow.rs:7:28}}
215+
{{#rustdoc_include ../../../../../hooq-macros/src/impls/flavor/presets/tracing.rs:7:33}}
163216
```
164217

165-
[`.with_context(...)`](https://docs.rs/anyhow/latest/anyhow/trait.Context.html#tymethod.with_context) メソッドを利用するために、 `anyhow::Context` トレイトをuseしています。
166-
218+
`#[tracing::instrument]` と併用する場合、 `#[hooq(tracing)]` が先に適用される必要があるため、 `#[tracing::instrument]` より上に `#[hooq(tracing)]` を書くことを推奨します。
167219

168220
使用例:
169221

170222
```rust
171-
{{#rustdoc_include ../../../../../mdbook-source-code/flavor-anyhow/src/main.rs}}
223+
{{#rustdoc_include ../../../../../mdbook-source-code/flavor-tracing/src/main.rs}}
172224
```
173225

174226
実行結果:
175227

176228
```bash
177-
{{#include ../../../../../mdbook-source-code/flavor-anyhow/tests/snapshots/test__flavor-anyhow.snap:8:13}}
229+
{{#include ../../../../../mdbook-source-code/flavor-tracing/tests/snapshots/test__flavor-tracing.snap:5:11}}
178230
```
179-
180-
## eyre / color-eyre
181-
182-
(WIP!準備中です)
183-
184-
## tracing
185-
186-
(WIP!準備中です)

hooq-macros/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ readme = "docs/README.md"
1616
proc-macro = true
1717

1818
[features]
19-
default = ["anyhow", "log"]
19+
default = ["anyhow", "log", "tracing", "eyre"]
2020
log = []
2121
anyhow = []
2222
consume-question = []
23+
tracing = []
24+
eyre = []
2325

2426
[dependencies]
2527
proc-macro-crate = "3.4.0"

0 commit comments

Comments
 (0)