Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are the generic functions and types stored in an rlib?

Tags:

generics

rust

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?

like image 229
F001 Avatar asked Jun 09 '15 07:06

F001


1 Answers

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.

like image 100
DK. Avatar answered Oct 19 '22 21:10

DK.