In C++, the templates can not be generated into dynamic libraries, we can only use them by header files.
In C#, generic functions and types can be interpreted by intermediate language in .NET.
Rust has no virtual machine, and the generics can be stored in the rlib
files. How does it managed to achieve this? What is the format of rlib files?
An rlib
is a regular static library (built in the ar
format) that contains additional metadata. That metadata contains, among other things, the complete, serialised abstract syntax tree (AST) for all generics and functions marked with #[inline]
.
It's a bit like if there was a C++ compiler that shoved a library's header files into the compiled binary, and then read them out again when linking against that library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With