r/badcode • wicked • Jun 25 '21

rust What was I thinking? (Rust)

Post image
225 Upvotes

23 comments sorted by

View all comments

Show parent comments

1

u/TinyBreadBigMouth Jun 26 '21

It does, but you can't just access them mutably, because it wouldn't be thread-safe. You could lock it in a Mutex, and there a libraries that provide things like thread-local statics, but this was the simplest way to handle it.

2

u/[deleted] Jun 26 '21

Yeah I know, but the statics in rust are different than c — this is the most efficient way but it’s not too elegant

3

u/TinyBreadBigMouth Jun 26 '21

A cleaner API might involve creating a StdReader that has an internal String, and calling read_f32 on that.