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 streaming / writers #5

Open
jkelleyrtp opened this issue Dec 26, 2021 · 5 comments
Open

Support streaming / writers #5

jkelleyrtp opened this issue Dec 26, 2021 · 5 comments

Comments

@jkelleyrtp
Copy link

It would be great to expose a write! compatible form of convert case in case an existing buffer is already provided.

@rutrum
Copy link
Owner

rutrum commented Dec 26, 2021

Can you give me an example of what you mean by this? That is, can you write some rust code explaining your use case?

@jkelleyrtp
Copy link
Author

jkelleyrtp commented Dec 27, 2021

Sure, I'm implementing something right now.

let mut out_buf = String::new();

write!(out_buf, "{}", Caser::ToSnake("CamelCase"))

So instead of calling ToString in places where do today, implement the write! trait for some item that does the conversion. This saves the need to allocate and de-allocate a string on the fly.

Additionally, looking through the code, it might be useful to have the writer be no-std compatible, or at least not allocate through something like SmallVec

@rutrum
Copy link
Owner

rutrum commented Dec 27, 2021

I'm still not totally following exactly the request, but I am welcome to make changes to decrease the number or allocations needed to do the conversion. Since you are looking at/implementing something, let me know what you think can be done so I can better understand what you are going for.

@jkelleyrtp
Copy link
Author

Right now the API of to_case() doesn't allow you to provide an existing string to write to. The extension I propose (and am willing to add) would allow you to provide your own String, ideally implemented through the display trait.

You have something similar internally with the Converter, but it's not exposed to the public API.

@rutrum
Copy link
Owner

rutrum commented Dec 27, 2021

I've just formally published version 0.5.0 version of this crate, which reflects the current state of the master branch of this repository. Check these most recent docs: https://docs.rs/convert_case/0.5.0/convert_case/index.html

Converter should be a public facing API.

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

2 participants