Repository: metacall/core (language: rust)

Issue:
Improve rs_port
The Rust port isn't complete. Not enough type support, no documentation, no useful tests, etc...

Here are the things I'm implementing through this issue:

- [x] Complete type support for returned types (multiple languages for full testing)
- [x] Complete type support for argument types (multiple languages for full testing)
- [x] Test for returned types
- [x] Test for argument types
- [x] Automatically shutdown Metacall
- [x] Extend Any types
- [x] Add generic support for cleaner usage
- [x] Switch back to stable Rust (unnecessary usage of nightly)
- [x] Automatically generate bindings with Bindgen from Metacall headers instead of doing manually
- [x] Detect and resolve memory leaks in the rs_port
- [x] Add documentation to be published on docs.rs



Discussion / hints:
In order to compile tests for debugging with valgrind you can do:
```cargo test --no-run```
It returns the location of generated binaries.

Then you can do something like:
```valgrind --show-reachable=no --show-possibly-lost=no --leak-check=full <file_path_here>```
There it goes my last commit. I completed my checklist. Dear reviewers, please state things you think should be changed in order to finalize this issue and publish a new version on crates.io.
So I have made bindgen part of cmake and outside of build.rs, let's see if test passes, it has sanitizers now.

Last thing on my side will be reviewing the current implementation and pushing to crates.

Fix patch:
diff --git a/source/ports/rs_port/Cargo.toml b/source/ports/rs_port/Cargo.toml
index 2da7b3775..7c6af3308 100644
--- a/source/ports/rs_port/Cargo.toml
+++ b/source/ports/rs_port/Cargo.toml
@@ -11,8 +11,6 @@ version = "0.4.0"
 
 [lib]
 crate-type = ["lib"]
-# Code examples used in documentation are environment dependent. Meaning they need a set of
-# stuff to be done before executing the codes. Therefore we should disable doctests.
 doctest = false
 edition = "2021"
 name = "metacall"
diff --git a/source/ports/rs_port/README.md b/source/ports/rs_port/README.md
index eb8793787..7c1006a6d 100644
--- a/source/ports/rs_port/README.md
+++ b/source/ports/rs_port/README.md
@@ -26,11 +26,11 @@ export function sum(a: number, b: number): number {
 
 `main.rs`
 ``` rust
-use metacall::{hooks, metacall, loaders};
+use metacall::{switch, metacall, loaders};
 
 fn main() {
     // Initialize Metacall at the top
-    let _metacall = hooks::initialize().unwrap();
+    let _metacall = switch::initialize().unwrap();
      
     // Load the file
     loaders::from_single_file("ts", "sum.ts").unwrap();
diff --git a/source/ports/rs_port/src/lib.rs b/source/ports/rs_port/src/lib.rs
index 60fc6707a..638e5186a 100644
--- a/source/ports/rs_port/src/lib.rs
+++ b/source/ports/rs_port/src/lib.rs
@@ -41,11 +41,11 @@
 //! Now let's jump into Rust:
 //!
 //! ```
-//! use metacall::{hooks, metacall, loaders};
+//! use metacall::{switch, metacall, loaders};
 //!
 //! fn main() {
 //!     // Initialize Metacall at the top
-//!     let _metacall = hooks::initialize().unwrap();
+//!     let _metacall = switch::initialize().unwrap();
 //!     
 //!     // Load the file (Checkout the loaders module for loading multiple files
 //!     // or loading from string)
@@ -78,13 +78,13 @@ pub(crate) use macros::private_macros::*;
 pub mod loaders;
 
 mod types;
-pub use hooks::initialize;
+pub use switch::initialize;
 
 #[doc(hidden)]
 pub mod macros;
 
 #[doc(hidden)]
-pub mod hooks;
+pub mod switch;
 pub use types::*;
 
 #[path = "metacall.rs"]
diff --git a/source/ports/rs_port/src/hooks.rs b/source/ports/rs_port/src/switch.rs
similarity index 100%
rename from source/ports/rs_port/src/hooks.rs
rename to source/ports/rs_port/src/switch.rs


Test patch:
diff --git a/source/ports/rs_port/tests/inlines_test.rs b/source/ports/rs_port/tests/inlines_test.rs
index 83ed69f2e..fa0f45e97 100644
--- a/source/ports/rs_port/tests/inlines_test.rs
+++ b/source/ports/rs_port/tests/inlines_test.rs
@@ -1,12 +1,11 @@
 use metacall::{
-    hooks,
-    loaders,
     inline::{node, py, ts},
+    loaders, switch,
 };
 
 #[test]
 fn inlines() {
-    let _d = hooks::initialize().unwrap();
+    let _d = switch::initialize().unwrap();
 
     if loaders::from_memory("py", "").is_ok() {
         py! {
diff --git a/source/ports/rs_port/tests/invalid_loaders_test.rs b/source/ports/rs_port/tests/invalid_loaders_test.rs
index 260af2b2b..e98418c23 100644
--- a/source/ports/rs_port/tests/invalid_loaders_test.rs
+++ b/source/ports/rs_port/tests/invalid_loaders_test.rs
@@ -1,9 +1,9 @@
-use metacall::{hooks, loaders, MetacallLoaderError};
+use metacall::{loaders, switch, MetacallLoaderError};
 use std::env;
 
 #[test]
 fn invalid_loaders() {
-    let _d = hooks::initialize().unwrap();
+    let _d = switch::initialize().unwrap();
 
     let scripts_dir = env::current_dir().unwrap().join("tests/scripts");
     let inavlid_file = scripts_dir.join("whatever.yeet");
diff --git a/source/ports/rs_port/tests/loaders_test.rs b/source/ports/rs_port/tests/loaders_test.rs
index e915f7188..75873d8c5 100644
--- a/source/ports/rs_port/tests/loaders_test.rs
+++ b/source/ports/rs_port/tests/loaders_test.rs
@@ -1,4 +1,4 @@
-use metacall::{hooks, loaders, metacall_no_arg};
+use metacall::{loaders, metacall_no_arg, switch};
 use std::{
     env,
     fs::{self, File},
@@ -50,7 +50,7 @@ fn load_from_file_test() {
 
 #[test]
 fn loaders() {
-    let _d = hooks::initialize().unwrap();
+    let _d = switch::initialize().unwrap();
 
     // Testing load_from_memory
     load_from_memory_test();
diff --git a/source/ports/rs_port/tests/metacall_exception_test.rs b/source/ports/rs_port/tests/metacall_exception_test.rs
index 4c85ddc9c..5933b59c0 100644
--- a/source/ports/rs_port/tests/metacall_exception_test.rs
+++ b/source/ports/rs_port/tests/metacall_exception_test.rs
@@ -1,9 +1,9 @@
-use metacall::{hooks, loaders};
+use metacall::{loaders, switch};
 use std::env;
 
 #[test]
 fn inlines() {
-    let _d = hooks::initialize().unwrap();
+    let _d = switch::initialize().unwrap();
 
     let tests_dir = env::current_dir().unwrap().join("tests/scripts");
     let js_test_file = tests_dir.join("script.js");
diff --git a/source/ports/rs_port/tests/metacall_test.rs b/source/ports/rs_port/tests/metacall_test.rs
index 8aa6e779b..82c0b2229 100644
--- a/source/ports/rs_port/tests/metacall_test.rs
+++ b/source/ports/rs_port/tests/metacall_test.rs
@@ -1,5 +1,5 @@
 use metacall::{
-    hooks, loaders, MetacallClass, MetacallException, MetacallFunction, MetacallFuture,
+    loaders, switch, MetacallClass, MetacallException, MetacallFunction, MetacallFuture,
     MetacallNull, MetacallObject, MetacallPointer, MetacallThrowable, MetacallValue,
 };
 use std::{collections::HashMap, env, fmt::Debug};
@@ -335,7 +335,7 @@ fn test_throwable() {
 
 #[test]
 fn metacall() {
-    let _d = hooks::initialize().unwrap();
+    let _d = switch::initialize().unwrap();
 
     let tests_dir = env::current_dir().unwrap().join("tests/scripts");
     let js_test_file = tests_dir.join("script.js");