Indeed:
lazy_static! {
static ref BUF: [[u8;1024]; 16] = [
[0;1024], [0;1024], [0;1024], [0;1024],
[0;1024], [0;1024], [0;1024], [0;1024],
[0;1024], [0;1024], [0;1024], [0;1024],
[0;1024], [0;1024], [0;1024], [0;1024]];
static ref BUF_INDEX: usize = 0;
}
(You'll need to re-implement a `push_str` method on arrays yourself though)> BUF is also visible to other parts of the program, correct? If so, it's not quite similar to the C example.
No, because it's not marked as `pub`, nobody outside the current module can access it.
Yes, of course. BTW: You can use a c2rust converter to convert a C code to it exact equivalent in Rust.
No, buf is not exported, so it's "static" in C terminology.
Yes, I know that is not exported. What I wanted to say is that in the C example, no one outside tmpstr(void) can access static char buf[16][1024].
In the Rust example I can access static ref BUF from fn main() function, for example.
Only because in that simple example, BUF was defined directly in the main module.
In a more realistic exemple, BUF and tmpstr would belong to their own module, with only tmpstr being exported (and then accessible). See: https://play.rust-lang.org/?version=stable&mode=debug&editio...
Can you just declare a static array and return a pointer pointing to any part of it? Like in the C example?
BUF is also visible to other parts of the program, correct? If so, it's not quite similar to the C example.