-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenforce-context.rs
More file actions
27 lines (22 loc) · 699 Bytes
/
Copy pathenforce-context.rs
File metadata and controls
27 lines (22 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//! How to force yourself to give context.
#![allow(clippy::missing_docs_in_private_items, reason = "Example")]
use ::macro_rules_attribute::apply;
use ::neuer_error::{Result, require_context, traits::*};
fn some_error() -> Result<bool, ::core::str::ParseBoolError> {
"".parse::<bool>()
}
fn no_context_required() -> Result<()> {
some_error()?;
Ok(())
}
#[apply(require_context)]
fn context_required() -> Result<()> {
some_error().context("compile error without this context")?;
Ok(())
}
#[apply(require_context)]
fn main() -> Result<()> {
no_context_required().context("compile error without this context")?;
context_required().context("compile error without this context")?;
Ok(())
}