by bascule · 9y ago · 0 comments
Here's one in particular:
In principal, this would allow us to statically allocate
a buffer sized for each particular closure.
Unfortunately, there is no size_of keyword in Rust,
and static initialization cannot invoke functions—
in this case the function size_of<T>() -> usize provided
by the Rust core library.
This can be solved by using the lazy_static crate:https://github.com/rust-lang-nursery/lazy-static.rs
From the description in the README:
Using this macro, it is possible to have statics that
require code to be executed at runtime in order to be
initialized.
Hey look, it's exactly what they need! It's also "no_std" compatible and can work just fine in a kernel-like context.Take this paper with a grain of salt: it's a bit dated at this point, and there are solutions for a number of the problems posed.
Also, lazy-static has been around for a long time. Releases first occurred in 2014! I'd be surprised if it had not been considered.
That said, Rust supports custom allocators now:
https://doc.rust-lang.org/book/custom-allocators.html
Write your own allocator and use Box.
I wouldn't be surprised if it hadn't been considered. The paper was released in 2015, so development may have begun in 2014. Furthermore, I don't believe the authors were engaged with the broader Rust community before this paper was released (they are today), so it's possible that there was no expert there to advise them about this approach. Also, discoverability of libraries was more of an issue back then, so it's plausible that they wouldn't have found it independently.
Edit: I apologize for the snark, but still, monospace for quoting doesn't add anything, and I don't see why people do it once they see it forces a side scroll on small screens. Please just use >
> because HN formats > text blocks > like this
> It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us, we were all going direct to Heaven, we were all going direct the other way – in short, the period was so far like the present period, that some of its noisiest authorities insisted on its being received, for good or for evil, in the superlative degree of comparison only.
> like
> this
Make sure to check out "japaric" on GitHub; they have built a lot of awesome tooling for Rust embedded stuff.