2 ms·
String is heap allocated by default, but String can be made from raw pointer to buffer and buffer length: https://doc.rust-lang.org/std/string/struct.String.htm
by drran 5y ago
String is heap allocated by default, but String can be made from raw pointer to buffer and buffer length: https://doc.rust-lang.org/std/string/struct.String.html#method.from_raw_parts https://doc.rust-lang.org/std/string/struct.String.html#meth... .
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.
- scoutt 5y ago> 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.
- littlestymaar 5y ago> 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&edition=2018&gist=5ab2b41b09a19806de5fdb0922a279ca https://play.rust-lang.org/?version=stable&mode=debug&editio...