Skip to content

Commit 75daef7

Browse files
author
Flix
committed
Fix doc-tests
1 parent 8f6a060 commit 75daef7

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/macros.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,50 @@
1010
/// ## Usage
1111
///
1212
/// Simple getters without type transformation:
13+
///
1314
/// ```rust
15+
/// # use contextual_errors::provided_attachments;
1416
/// #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
1517
/// enum Retryable { Yes, No }
1618
///
1719
/// provided_attachments!(
1820
/// retryable(single: Retryable) -> Option<&Retryable> { |v| v };
1921
/// );
2022
/// ```
23+
///
2124
/// This will create a method `fn retryable(&self) -> Option<&Retryable>` on `CtxError`.
2225
///
2326
/// You can also make use of the transformation expression that will be applied to the attachment
24-
/// before returning it: ```rust
27+
/// before returning it:
28+
///
29+
/// ```rust
30+
/// # use contextual_errors::provided_attachments;
2531
/// #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
2632
/// enum Retryable { Yes, No }
2733
///
2834
/// provided_attachments!(
2935
/// retryable(single: Retryable) -> Retryable { |retry| retry.copied().unwrap_or(Retryable::No) };
3036
/// );
3137
/// ```
38+
///
3239
/// This will create a method `fn retryable(&self) -> Retryable` on `CtxError`. The closure receives
3340
/// the `Option<&Retryable>` and returns a `Retryable`.
3441
///
3542
/// Finally, you can also retrieve multiple attachments of the same type and transform the iterator
36-
/// into your return type: ```rust
43+
/// into your return type:
44+
///
45+
/// ```rust
46+
/// # use contextual_errors::provided_attachments;
3747
/// #[derive(Debug, PartialEq, Clone)]
3848
/// struct UserInfo(String);
3949
///
4050
/// provided_attachments!(
41-
/// user_info(multiple: UserInfo) -> String { |iter| iter.map(|UserInfo(s)| s).collect() };
51+
/// user_info(multiple: UserInfo) -> String { |iter| iter.map(|UserInfo(s)| s.as_str()).collect() };
4252
/// );
43-
/// This will create a method `fn user_info(&self) -> String` on `CtxError`, which collects all `UserInfo` attachments, unpacks them and collects them into a single `String`.
4453
/// ```
54+
///
55+
/// This will create a method `fn user_info(&self) -> String` on `CtxError`, which collects all
56+
/// `UserInfo` attachments, unpacks them and collects them into a single `String`.
4557
#[macro_export]
4658
macro_rules! provided_attachments {
4759
// Declare rule for single attachment.

0 commit comments

Comments
 (0)