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!準備中です)
0 commit comments