Daniel-Liu-c0deb0t / uwu

fastest text uwuifier in the west
https://crates.io/crates/uwuify
MIT License
1.36k stars 41 forks source link

How to use lib with strings? #5

Closed ShadowMitia closed 3 years ago

ShadowMitia commented 3 years ago

Hello!

I want to use the lib in a bot, to try out, but it seems to be able to only use files/stdin. Is there an easy way to use strings with this lib?

Thanks in advance!

Daniel-Liu-c0deb0t commented 3 years ago

right now this isn't possible. ill need to publish the core uwuify function as a separate crate so you can include it in rust programs, but i might not get around to it

ShadowMitia commented 3 years ago

Fair enough^^ I'm using uwu_ify_sse from the crate for now, it's good enough for me right now^^

Daniel-Liu-c0deb0t commented 3 years ago

oh cool, yes that works too

just make sure you pass large buffers for the temp_bytes cuz in the worst case, it is possible for each of the 4 passes to approximately double the size of the input buffer. right now it will just panic if you pass it a buffer that is too small. see src/main.rs for an example of how uwu_ify_sse is called

ShadowMitia commented 3 years ago

Thanks for the tip! I didn't understand why you need two temp buffers. Would you mind clarifying that?

Daniel-Liu-c0deb0t commented 3 years ago

sure. each pass uses one of the temp buffers for input and the other for output. of course, you could make the bytes buffer mutable and overwrite it, but i thought it would be easier for the user to not have to worry about the bytes buffer has a certain size or alignment (eventually i didn't require a certain alignment for any of the buffers though) or having the stuff they pass in be modified. also, the temp buffers were supposed to be an implementation detail (ie, allocated in the uwu_ify_sse function, so you would only pass in a immutable bytes slice with no requirements on its size), but to reduce allocations i moved it out.

Daniel-Liu-c0deb0t commented 3 years ago

alright, just published a new release that should make this a lot easier to use

you can put uwuify = "^0.2" in your Cargo.toml to include uwuify as a library. take a look at the readme for instructions on how to use it. also there's docs at: https://docs.rs/uwuify/0.2.0/uwuifier/

jRimbault commented 3 years ago

Would you be comfortable exposing that kind of API ?

pub fn uwuify(input: &str) -> String;
Daniel-Liu-c0deb0t commented 3 years ago

sure, im working on it

Edit: done and published in version 0.2.1

ShadowMitia commented 3 years ago

Oh that example is great, thanks!