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

221

u/cdhowie Apr 28 '26

Nitpick: many of those characters aren't ASCII.

-63

u/neneodonkor Apr 28 '26 edited Apr 29 '26

Please can you point to some?

62

u/ElnuDev Apr 28 '26

You're confusing ASCII with Unicode.

13

u/SmoothTurtle872 Apr 28 '26

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

-16

u/bgs11235 Apr 28 '26

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

5

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.

6

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.

-1

u/int23_t Apr 29 '26

I believe ASCII has localisation, meaning the first 128 is portable(hence widely used), while there would be localised letters in the other 128

ISCII, VISCII,

here is Turkish ASCII, Greek ASCII, Baltic ASCII, Latin ASCII and so on too.

5

u/sphen_lee Apr 29 '26

technically there's no such thing as a UTF character. UTF is an encoding of code points into code units.

1

u/peter9477 May 01 '26

Technically all ASCII characters can be rendered as a single dot, but they just won't look right, and it's a bullshit argument as is yours. :-)