Hello Mansour,
Thank you for the kind words and the excellent questions!
To put it simply:
It works exactly like standard C/C++ extensions.Here are the specific answers to your points:
1. Is it an extension like C/C++ (DLLs)?Yes, exactly.
You write the code in Rust, and when you compile it (using `
cargo build --release`), it generates a shared library (`
.dll` on Windows, `
.so` on Linux, `
.dylib` on macOS). You then load this DLL in Ring using `
loadlib()`.
2. Are they scripts that fire Rust executables?No.
This is not a wrapper that runs external `
.exe` files. It uses
FFI (Foreign Function Interface). The Rust code runs inside the Ring process, sharing the same memory. This means it is extremely fast—just as fast as a C extension.
3. How is it used by Ring programmers?The examples in my post showed the
Rust side (how to create the extension).
On the
Ring side, you use it just like any other DLL extension.
For example, if you build the basic example:
cd examples/basic
cargo build --release
ring test.ring
Ring Code (test.ring):# Load the appropriate library for each OS
if isWindows()
loadlib("target/release/basic_extension.dll")
but isMacOSX()
loadlib("target/release/libbasic_extension.dylib")
else
loadlib("target/release/libbasic_extension.so")
ok
# Now we can call the functions defined in Rust
? rust_hello() # Prints: Hello from Rust!
? rust_add(10, 20) # Prints: 30
? rust_greet("Mansour") # Prints: Hello, Mansour!
4. Is it a low-level solution?It is a tool for
extension developers.
- The Developer: Needs to know some Rust to write the extension logic (instead of writing C).
- The Ring User: Doesn't need to know Rust. They just `loadlib("...")` and use the functions as if they were native Ring functions.
The `
examples/basic/` folder demonstrates working with numbers, strings, lists, and C pointers. You can use it as a template for your own extensions.
I hope this clarifies the architecture! It is essentially a modern way to build Ring extensions without writing C code—while gaining access to the entire Rust ecosystem (150,000+ crates).
Best regards,
Youssef