Skip to content

Commit 27fcd5b

Browse files
committed
Rename macro to context
1 parent 1d599bd commit 27fcd5b

19 files changed

+42
-40
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
An attribute macro to add context to errors from a function.
1212

1313
```
14-
#[error_context("failed to parse config at `{}`", path.display())]
14+
#[context("failed to parse config at `{}`", path.display())]
1515
pub fn parse_config(path: &Path) -> anyhow::Result<u32> {
1616
let text = read_to_string(path)?;
1717
Ok(text.parse()?)

examples/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::fs::read_to_string;
22
use std::path::Path;
33

4-
use fn_error_context::error_context;
4+
use fn_error_context::context;
55

6-
#[error_context("failed to parse config at `{}`", path.as_ref().display())]
6+
#[context("failed to parse config at `{}`", path.as_ref().display())]
77
pub fn parse_config(path: impl AsRef<Path>) -> anyhow::Result<u32> {
88
let text = read_to_string(path.as_ref())?;
99
Ok(text.parse()?)

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
// #![deny(missing_docs)]
2+
13
extern crate proc_macro;
24

35
use proc_macro::TokenStream;
46
use quote::quote;
57

68
#[proc_macro_attribute]
7-
pub fn error_context(args: TokenStream, input: TokenStream) -> TokenStream {
9+
pub fn context(args: TokenStream, input: TokenStream) -> TokenStream {
810
let args: proc_macro2::TokenStream = args.into();
911
let mut input = syn::parse_macro_input!(input as syn::ItemFn);
1012

tests/arg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use fn_error_context::error_context;
1+
use fn_error_context::context;
22

3-
#[error_context("context")]
3+
#[context("context")]
44
fn do_stuff(arg: u32) -> anyhow::Result<()> {
55
anyhow::bail!("error {}", arg)
66
}

tests/arg_pattern.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use fn_error_context::error_context;
1+
use fn_error_context::context;
22

3-
#[error_context("context")]
3+
#[context("context")]
44
fn do_stuff((x, y): (i32, u32)) -> anyhow::Result<()> {
55
anyhow::bail!("error {} {}", x, y)
66
}

tests/as_ref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use fn_error_context::error_context;
1+
use fn_error_context::context;
22

3-
#[error_context("context {}", arg.as_ref())]
3+
#[context("context {}", arg.as_ref())]
44
fn do_stuff(arg: impl AsRef<str>) -> anyhow::Result<()> {
55
anyhow::bail!("error {}", arg.as_ref())
66
}

tests/failure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use fn_error_context::error_context;
1+
use fn_error_context::context;
22

3-
#[error_context("context")]
3+
#[context("context")]
44
fn do_stuff() -> failure::Fallible<()> {
55
failure::bail!("error")
66
}

tests/fmt_args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use fn_error_context::error_context;
1+
use fn_error_context::context;
22

3-
#[error_context("context {}", arg)]
3+
#[context("context {}", arg)]
44
fn do_stuff(arg: u32) -> anyhow::Result<()> {
55
anyhow::bail!("error {}", arg)
66
}

tests/fmt_missing_arg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use fn_error_context::error_context;
1+
use fn_error_context::context;
22

3-
#[error_context("{}")]
3+
#[context("{}")]
44
fn do_stuff() -> anyhow::Result<()> {
55
anyhow::bail!("error")
66
}

tests/fmt_missing_arg.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: 1 positional argument in format string, but no arguments were given
2-
--> $DIR/fmt_missing_arg.rs:3:18
2+
--> $DIR/fmt_missing_arg.rs:3:12
33
|
4-
3 | #[error_context("{}")]
5-
| ^^
4+
3 | #[context("{}")]
5+
| ^^

0 commit comments

Comments
 (0)