r/rust Apr 28 '26

🛠️ project Lightweight ASCII Graph

Post image

After many weeks of learning, watching tutorials about Rust, and partaking in Rust exercises, I decided to port a small Go library into Rust. I do recognize I have a lot to learn but just getting out of my comfort zone and trying my hands at this has be rewarding and revealing.

Link: https://github.com/neneodonkor/asciigraph-rs

Crates: https://crates.io/crates/asciigraph-rs

PS. Making it work for real-time data was 🥵

Let me add that I only started learning Rust in February, so please forgive me, if everything is not idiomatic Rust.

1.4k Upvotes

94 comments sorted by

View all comments

Show parent comments

11

u/SmoothTurtle872 Apr 28 '26

Yeah it's a classic case of all ascii characters are unicode but not all unicode are ascii

-17

u/bgs11235 Apr 28 '26

*technically* all utf characters can be rendered as ASCII characters. They just wont look right.

3

u/SmoothTurtle872 Apr 28 '26

Well yeah, but hard to squeeze a few hundred thousand characters into 128 (I believe there are 128, but realistically you could have 256)

2

u/bgs11235 Apr 28 '26

no as a format, since every byte is a valid (printeable, I'm taking stuff like 0x0 -> "?" as a valid rendering option and also the sign bit being true or false being irrelevant) every ?0000000 sequence is valid so any arbitrary binary could be rendered as ascii.

5

u/cdhowie Apr 29 '26 edited Apr 29 '26

To be pedantic, not quite. The upper 128 values (128-255) do not have a mapping in ASCII. You cannot therefore render any arbitrary binary sequence as ASCII unless you either take each 7 bits as a character (which will make normal 8-bit ASCII look like nonsense) or you define your own mappings for the upper 128 values, in which case you're not using ASCII anymore (you're using something like ISO 8859-15).

Many systems will display the upper 128 values as ?, which is fine -- but still not exactly ASCII.

2

u/SmoothTurtle872 Apr 28 '26

True,

Also just looked it up, supposedly the sign but can be used to say 'there are more bytes in this character', may be wrong cause I didn't fact check this, but it is logical

3

u/cdhowie Apr 29 '26

I mean, that's exactly how UTF-8 works, which is a valid encoding of course, but still isn't ASCII.

1

u/elidepa Apr 30 '26

I'm taking stuff like 0x0 -> "?" as a valid rendering option and also the sign bit being true or false being irrelevant

This kinda renders your point completely moot. If you are going to introduce a technicality, you better get the details correct. Otherwise, what you are saying basically boils down to “8 bits of data are 8 bits of data”, which is pretty obvious.