Skip to content

Commit

Permalink
Store default_log_filter as Cow<str>
Browse files Browse the repository at this point in the history
In the future we anticipate adjusting the default filter to use, an
effort that will in part piggy-back on the existing default_log_filter
attribute. Swap its type to a Cow, so that if we use a statically
defined default, we are not forced to allocate.
  • Loading branch information
d-e-s-o committed Jan 12, 2025
1 parent a98f548 commit c91596c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright (C) 2019-2023 Daniel Mueller <[email protected]>
// Copyright (C) 2019-2025 Daniel Mueller <[email protected]>
// SPDX-License-Identifier: (Apache-2.0 OR MIT)

extern crate proc_macro;

use std::borrow::Cow;

use proc_macro::TokenStream;
use proc_macro2::TokenStream as Tokens;

Expand Down Expand Up @@ -93,7 +95,7 @@ fn try_test(attr: TokenStream, input: ItemFn) -> syn::Result<Tokens> {

#[derive(Debug, Default)]
struct AttributeArgs {
default_log_filter: Option<String>,
default_log_filter: Option<Cow<'static, str>>,
}

impl AttributeArgs {
Expand Down Expand Up @@ -132,7 +134,7 @@ impl AttributeArgs {

if let Expr::Lit(lit) = &name_value.value {
if let Lit::Str(lit_str) = &lit.lit {
*arg_ref = Some(lit_str.value());
*arg_ref = Some(Cow::from(lit_str.value()));
}
}

Expand Down

0 comments on commit c91596c

Please sign in to comment.