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

Support Cow<'static, str> for Readable #25

Open
benruijl opened this issue Jul 24, 2022 · 4 comments
Open

Support Cow<'static, str> for Readable #25

benruijl opened this issue Jul 24, 2022 · 4 comments

Comments

@benruijl
Copy link

I have a struct that contains a Cow<'static, str> member. This struct cannot implement Readable at the moment, since Readable is not able to create a borrow that is static. Would it be possible to make Readable create an owned clone of the string in this case?

@benruijl benruijl changed the title Support Cow<'static, str> Support Cow<'static, str> for Readable Jul 24, 2022
@koute
Copy link
Owner

koute commented Jul 24, 2022

Yes, that could be special-cased inside of the derive macro.

@naomijub
Copy link

Wouldn't it be better to implement the trait manually in this case? It seems a very special case with possible different intents

@koute
Copy link
Owner

koute commented Jul 25, 2022

Wouldn't it be better to implement the trait manually in this case? It seems a very special case with possible different intents

You'd have to implement the trait for the whole struct, which is not very ergonomic. An actually viable alternative would be to make a newtype (e.g. StaticCowStr) and manually implement the train yourself only on that. But I think it wouldn't be a bad idea to make Cow<'static, str> work by default anyway.

@naomijub
Copy link

In the past I've done the new type strategy for um implemented traits on types. Mostly works and is flex according to the demanded solution

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

3 participants