4 ms·
FWIW, much of the verbosity in this post is optional, e.g. the very first example could be static mut base: uint = 0x200000; pub extern "C" fn malloc(len:
by dbaupp 13y ago
FWIW, much of the verbosity in this post is optional, e.g. the very first example could be
static mut base: uint = 0x200000;
pub extern "C" fn malloc(len: uint) -> *mut u8 {
base as *mut u8
}
(I'll admit the second can be reduced less, since it's actually doing real work: basically just dropping the `: uint` on the `let ret`, dropping the `return` and associated `;`, and removing the () on the if condition.)
I guess the major source of verbosity is the `extern "C"`, which, fortunately, is only necessary when one requires a function uses the C ABI/calling-convention; in the overwhelmingly common case one writes `pub fn foo(...)` which will use the Rust ABI (and it gets reduced to just `fn foo(...)` if the function can be private to a module).