Skip to content

Commit

Permalink
style: Run cargo fmt against new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed May 8, 2023
1 parent 282bd78 commit 6ed92b6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
29 changes: 14 additions & 15 deletions tracing-attributes/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,17 @@ impl Parse for EventArgs {
let content;
let _ = syn::parenthesized!(content in input);
let mut result = Self::default();
let mut parse_one_arg =
|| {
let lookahead = content.lookahead1();
if lookahead.peek(kw::level) {
if result.level.is_some() {
return Err(content.error("expected only a single `level` argument"));
}
result.level = Some(content.parse()?);
} else if result.mode != FormatMode::default() {
return Err(content.error("expected only a single format argument"));
} else if let Some(ident) = content.parse::<Option<Ident>>()? {
match ident.to_string().as_str() {
let mut parse_one_arg = || {
let lookahead = content.lookahead1();
if lookahead.peek(kw::level) {
if result.level.is_some() {
return Err(content.error("expected only a single `level` argument"));
}
result.level = Some(content.parse()?);
} else if result.mode != FormatMode::default() {
return Err(content.error("expected only a single format argument"));
} else if let Some(ident) = content.parse::<Option<Ident>>()? {
match ident.to_string().as_str() {
"Debug" => result.mode = FormatMode::Debug,
"Display" => result.mode = FormatMode::Display,
"Raw" => result.mode = FormatMode::Raw,
Expand All @@ -183,9 +182,9 @@ impl Parse for EventArgs {
"unknown event formatting mode, expected either `Debug`, `Display`, or `Raw`",
)),
}
}
Ok(())
};
}
Ok(())
};
parse_one_arg()?;
if !content.is_empty() {
if content.lookahead1().peek(Token![,]) {
Expand Down
8 changes: 4 additions & 4 deletions tracing-attributes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ mod expand;
/// 42
/// }
/// ```
///
///
/// If the value being returned implements `tracing::field::Value`, you can optionally record it
/// in its raw form using `ret(Raw)`:
///
///
/// ```
/// # use tracing_attributes::instrument;
/// #[instrument(ret(Raw))]
Expand Down Expand Up @@ -305,11 +305,11 @@ mod expand;
/// Ok(())
/// }
/// ```
///
///
/// If you're returning a `Result<T, E>` and `E` implements [`std::error::Error`], you can
/// record the raw error value using `err(Raw)`. This can be useful when paired with a subscriber
/// which specially handles errors, like `tracing_opentelemetry`:
///
///
/// ```
/// # use tracing_attributes::instrument;
/// #[instrument(err(Raw))]
Expand Down
11 changes: 9 additions & 2 deletions tracing-attributes/tests/ret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ fn test_ret_and_err() {
.with_fields(
expect::field("error")
.with_value(&tracing::field::display(u8::try_from(1234).unwrap_err()))
.and(expect::field("message").with_value(&tracing::field::display(u8::try_from(1234).unwrap_err())))
.and(
expect::field("message").with_value(&tracing::field::display(
u8::try_from(1234).unwrap_err(),
)),
)
.only(),
)
.at_level(Level::ERROR),
Expand Down Expand Up @@ -244,7 +248,10 @@ fn test_ret_and_ok() {
.with_fields(
expect::field("return")
.with_value(&tracing::field::debug(u8::try_from(123).unwrap()))
.and(expect::field("message").with_value(&tracing::field::debug(u8::try_from(123).unwrap())))
.and(
expect::field("message")
.with_value(&tracing::field::debug(u8::try_from(123).unwrap())),
)
.only(),
)
.at_level(Level::INFO),
Expand Down

0 comments on commit 6ed92b6

Please sign in to comment.