Skip to content

AsRef<str> on paths / attributes should be replaced with std::fmt::Display #1277

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

Open
TroyKomodo opened this issue Apr 28, 2025 · 0 comments

Comments

@TroyKomodo
Copy link

As the title says, currently has a few apis where the function looks like this

pub fn field_attribute<P, A>(&mut self, path: P, attribute: A) -> &mut Self
where
    P: AsRef<str>,
    A: AsRef<str>,
{
    self.field_attributes
        .insert(path.as_ref().to_string(), attribute.as_ref().to_string());
    self
}

Internally this is calling to_string(), so we should simply require the Path or Attribute implement std::fmt::Display

I am using quote! to generate rust attributes

prost.field_attribute(
    &field.full_name,
    quote!(#[serde(serialize_with = #serialize_with)]).to_string(),
);

and TokenStream impls Display but not AsStr<str> .

this isnt a major issue since i can just call to_string() on my side, I just wanted to open this issue to see if we can fit this into a maybe #624 release

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

No branches or pull requests

1 participant