From 5f4dbe65685906eaec39a3675151cc5aa7e7570d Mon Sep 17 00:00:00 2001 From: Maxim Zhiburt Date: Mon, 25 Mar 2024 01:22:01 +0300 Subject: [PATCH] tabled_derive/ Fix issue with Cow usage --- tabled/Cargo.toml | 2 +- tabled/tests/derive/derive_test.rs | 9 +++++++++ tabled_derive/src/lib.rs | 8 ++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tabled/Cargo.toml b/tabled/Cargo.toml index c52a4e4d..d39a0eea 100644 --- a/tabled/Cargo.toml +++ b/tabled/Cargo.toml @@ -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" diff --git a/tabled/tests/derive/derive_test.rs b/tabled/tests/derive/derive_test.rs index d27e43ee..e742583f 100644 --- a/tabled/tests/derive/derive_test.rs +++ b/tabled/tests/derive/derive_test.rs @@ -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() { diff --git a/tabled_derive/src/lib.rs b/tabled_derive/src/lib.rs index ccfb65b0..26a1f355 100644 --- a/tabled_derive/src/lib.rs +++ b/tabled_derive/src/lib.rs @@ -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) } @@ -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))])