A playground for experiments with Rust inside PG extension.
cd pg
make install
create extension pgr;
select hello_rust();This example calls a Rust function hello_world() inside PG that:
- Creates a C compatible string with safe Rust.
- Allocates a memory chunk using PostgreSQL allocator with unsafe Rust.
- Copies the string from the Rust memory to the palloced one and attaches the pointer and some additional information to
PgMemoryChunkstructure. - Returns
PgMemoryChunk(it has a C ABI) to PG function, retrieves data and prints the string.
We should not care about GC in Rust as its compiler automatically adds deallocations when the objects run out of the scope.