Skip to content

Commit

Permalink
tabled_derive/ Fix issue with Cow usage
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiburt committed Mar 25, 2024
1 parent fa06ecf commit 5f4dbe6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tabled/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ macros = ["std"]

[dependencies]
papergrid = { version = "0.11", default-features = false }
tabled_derive = { version = "0.7", optional = true }
tabled_derive = { path = "../tabled_derive", optional = true }
ansi-str = { version = "0.8", optional = true }
ansitok = { version = "0.2", optional = true }
unicode-width = "0.1"
Expand Down
9 changes: 9 additions & 0 deletions tabled/tests/derive/derive_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,15 @@ fn test_skip_enum_0() {
assert_eq!(Letters::Digit.fields(), vec!["", ""]);
}

#[test]
fn test_display_with_2() {
#[derive(tabled::Tabled)]
struct Struct<'a> {
#[tabled(display_with("std::path::Path::display"))]
path: &'a std::path::Path,
}
}

mod __ {
#[test]
fn dont_import_the_trait() {
Expand Down
8 changes: 4 additions & 4 deletions tabled_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,12 @@ fn info_from_variant(
},
};

let call = match args {
let result = match args {
Some(args) => use_function(&args, func),
None => use_function_no_args(func),
};

quote! { ::std::borrow::Cow::from(#call) }
quote! { ::std::borrow::Cow::from(format!("{}", #result)) }
} else {
let default_value = "+";
quote! { ::std::borrow::Cow::Borrowed(#default_value) }
Expand Down Expand Up @@ -440,12 +440,12 @@ fn get_field_fields(field: &TokenStream, attr: &Attributes) -> TokenStream {
},
};

let call = match args {
let result = match args {
Some(args) => use_function(&args, func),
None => use_function_no_args(func),
};

return quote!(vec![::std::borrow::Cow::from(#call)]);
return quote!(vec![::std::borrow::Cow::from(format!("{}", #result))]);
}

quote!(vec![::std::borrow::Cow::Owned(format!("{}", #field))])
Expand Down

0 comments on commit 5f4dbe6

Please sign in to comment.