Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added FmtConst impl for String and Vec<Primitive> #185

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jean-airoldie
Copy link

@jean-airoldie jean-airoldie commented Nov 24, 2019

This allows the user to user owned types for dynamic code generation.

Here is a example where this is required:

let mut bldr = phf_codegen::Map::new();
// In this case symbol_ids is a HashMap<String, u32> whose content is only known
// at runtime.
for (symbol, id) in symbol_ids {
    bldr.entry(symbol, &id.to_string());
}
let display = bldr.build().to_string();

Previously the user would have to leak the String to get a &'static str.

I also ran rustfmt, which explains some of the diff.

This allows the user to user owned types for dynamic code generation.
@s3bk
Copy link

s3bk commented Feb 1, 2020

yes please. just ran into this while attempting to update.

@neandrake
Copy link
Contributor

I ran into the lack of FmtConst implementation for String while updating from 0.7 to 0.8. I confirmed that with a 1-line change to add the implementation and my previous output from 0.7 matches the new output from 0.8

delegate_debug!(String);

@@ -111,6 +111,19 @@ delegate_debug!(u128);
delegate_debug!(i128);
delegate_debug!(bool);

delegate_debug!(String);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency I would probably move this one up above under the delegate_debug!(str); line then have this next grouping be for Vec<>(). Would it make sense to have Vec<String> as well?

delegate_debug!(Vec<i64>);
delegate_debug!(Vec<u128>);
delegate_debug!(Vec<i128>);
delegate_debug!(Vec<bool>);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delegate_debug!() is not correct for Vec<_> because it prints an array literal.

@JohnTitor
Copy link
Member

I've merged the support for String hence the remaining task is how we deal with Vec<T>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants