rutrum / convert-case

Converts to and from various cases.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support streaming / writers

jkelleyrtp opened this issue · comments

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

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

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

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.

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.

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.