Hear me out, at the moment, rust can use
extern "C"
to import programs from compiled C libraries
as such, what if we allowed the same but with compiled rust libs, perhaps not an extern "Rust"
though perhaps a more native approach, downloading a static (or dynamic) library and then having a .rs file that acts kind of akin to a .d.ts file in typescript, declaring the functions with types and all of that cool stuff. (I am aware all of that would require each exported function to have a #[no_mangle]
before it (or adding a #[no_mangle]
on a mod to apply for all of its children, allowing the lib export of modules, or the introduction of a #[mangle]
which has the opposite effect of mangling functions that'd otherwise be untangled), as such might I suggest that libraries have no_mangle as the default and binaries do not, in order to keep the benefits of mangling and allow libs to link with binaries with little change)
however each of those functions are implemented in the static library, and a compiled file and then link into the lib, creating what is essentially a Rust to Rust ABI, allowing for a fast and small distribution of libraries.
This would give the #[no_mangle]
macro more use than for unsafe FFI bindings, instead allowing for safe rust to rust bindings aswell
for example, cargo
could download these definition files, and a compiled lib file uploaded to crates.io
, a git repo, etc.
This could increase the speed and likely reduce initial compile times on projects that use a lot of libraries (it may also substantially decrease data usage). An it would detach a reliance on cargo
as a build system and allows easy of distribution of rust libs.
This sound like I'm suggesting rust header files, which isn't wrong, but there are many benefits to it and a system like such, there is probably a better way to do it than what I've suggested though this is what came to my head and if anyone has a better way of achieving the same goal, I encourage you to say it below.
TL:DR; it would be cool to have a .d.rs to declare functions in a static lib to allow code to be linked with them (assuming the no_mangle
option is used or becomes default)
edit: my brain is weird, and just spits out ideas, and grammar