bytes icon indicating copy to clipboard operation
bytes copied to clipboard

Consider providing "string" to int conversion

Open carllerche opened this issue 5 years ago • 7 comments

Basically: https://linux.die.net/man/3/atoi

std already provides such a conversion from &str but not directly from &[u8]

carllerche avatar Dec 03 '19 18:12 carllerche

Looks like this crate implemented this functionality. Shall this crate just re-export?

rizsotto avatar Jan 25 '20 11:01 rizsotto

The goal of bytes is to provide the utilities itself and only depend on other crates in rare cases. Looking at atoi, it also seems to have heavy reliance on traits, which is not a direction we want to go.

carllerche avatar Jan 25 '20 16:01 carllerche

Thanks @carllerche for your response. I see what you are saying... On the other hand, serde-json is already depends on atoi crate. So for a user to write a microservice, these dependencies will be pulled in anyway. And killing the traits in atoi could be a nice improvement on that crate. Could you make a ticket on atoi with your suggestion to improve it?

rizsotto avatar Jan 26 '20 03:01 rizsotto

On the other hand, serde-json is already depends on atoi crate. So for a user to write a microservice, these dependencies will be pulled in anyway.

Note that not all users of this crate are writing web services.

Ralith avatar Jan 26 '20 03:01 Ralith

On the other hand, serde-json is already depends on atoi crate. So for a user to write a microservice, these dependencies will be pulled in anyway.

Note that not all users of this crate are writing web services.

Yeah, that's true. The point I was trying to make is to reduce the effort to implement the same functionality. And it looks like that atoi is trusted by the serde-json authors. So, why not further improve that crate with this use case too? That would reduce the bloat (duplicate code) for web service authors.

But I don't want to push anything on anybody. Just thought to create a ticket on atoi crate could be good... I find it hard to get those insights that users of my code have. (What are the pain points? Can it be more simple? etc...)

rizsotto avatar Jan 26 '20 04:01 rizsotto

I don't see atoi in the list of serde-json dependencies?

carllerche avatar Jan 26 '20 04:01 carllerche

I also don't think there is anything "wrong" with how atoi is designed, it just isn't the direction for bytes. It is similar to how byteorder uses traits and bytes does not. There are different use cases / constraints.

carllerche avatar Jan 26 '20 04:01 carllerche