Skip to content

yilabs/librust_interop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

librust_interop

Rust interop with other programming languages: C, D, ... etc.

Mainly to make high performant, memory safe Rust libraries available to other languages users.

Recently wrapped:

Note:

Right now:

  • only u64 is used as key type, and value type
  • so for value type: only pass integer type or pointer type to the container.

We use the same memory management method as liblfdsd: https://github.com/mw66/liblfdsd#memory-management-remember-this-is-a-thin-wrapper-lib-in-d

Let Rust's be Rust's, and let D's be D's, i.e.

  • Rust manage Rust's memory (the container), and
  • D manage D's memory (the objects)

The only thing interfacing between Rust and D is the simple uintptr_t (void*) as value, so to use this D library:

all primitive types (whose .sizeof upto pointer size on the target machine) | class (pointer)'s value are stored as value of uintptr_t everything else, i.e. all (fat) objects' address are stored as value of uintptr_t

The only extra requirement on the D side is to keep reference to those fat objects to avoid it being GC-ed before being pop-ed.

(Just as: don't push a stack var into any-type-of queue, and pop it after the stack is gone -- this is the responsibility of the programmer, not the container.)

That's all.

And please remember to keep a reference on the D side of the fat objects you put in the container:

Pre-req: