Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions source/ports/rs_port/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
[package]
authors = ["Mahdi Sharifi <devraymondsh@gmail.com>", "Vicente Eduardo Ferrer Garcia <vic798@gmail.com>", "Swarnim Arun <swarnimarun11@gmail.com>"]
authors = [
"Mahdi Sharifi <devraymondsh@gmail.com>",
"Vicente Eduardo Ferrer Garcia <vic798@gmail.com>",
"Swarnim Arun <swarnimarun11@gmail.com>",
]
description = "Call NodeJS, TypeScript, Python, C#, Ruby... functions from Rust (a Rust Port for MetaCall)."
edition = "2021"
keywords = ["ffi", "polyglot", "metacall", "inter-language", "polyglot-programming"]
keywords = [
"ffi",
"polyglot",
"metacall",
"inter-language",
"polyglot-programming",
]
license = "Apache-2.0"
name = "metacall"
readme = "README.md"
repository = "https://github.com/metacall/core/tree/develop/source/ports/rs_port"
version = "0.5.3"
version = "0.5.5"

[lib]
crate-type = ["lib"]
Expand All @@ -23,7 +33,4 @@ metacall-inline = { version = "0.2.0", path = "./inline" }
metacall-sys = { version = "0.1.2", path = "./sys" }

[workspace]
members = [
"inline",
"sys",
]
members = ["inline", "sys"]
29 changes: 2 additions & 27 deletions source/ports/rs_port/src/load.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
bindings::{metacall_clear, metacall_load_from_file, metacall_load_from_memory},
cstring_enum,
types::MetaCallLoaderError,
types::{self, MetaCallLoaderError},
};
use std::{
ffi::CString,
Expand All @@ -10,32 +10,7 @@ use std::{
path::{Path, PathBuf},
ptr::null_mut,
};

pub enum Tag {
C,
Cobol,
Crystal,
CSharp,
Dart,
Deno,
Extension,
File,
Java,
Julia,
JavaScript,
JSM,
Kind,
LLVM,
Lua,
Mock,
NodeJS,
Python,
Ruby,
RPC,
Rust,
TypeScript,
Wasm,
}
pub use types::Tag;

impl fmt::Display for Tag {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
25 changes: 25 additions & 0 deletions source/ports/rs_port/src/types/metacall_tags.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pub enum Tag {
C,
Cobol,
Crystal,
CSharp,
Dart,
Deno,
Extension,
File,
Java,
Julia,
JavaScript,
JSM,
Kind,
LLVM,
Lua,
Mock,
NodeJS,
Python,
Ruby,
RPC,
Rust,
TypeScript,
Wasm,
}
2 changes: 2 additions & 0 deletions source/ports/rs_port/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod metacall_future;
mod metacall_null;
mod metacall_object;
mod metacall_pointer;
mod metacall_tags;
mod metacall_value;

pub use metacall_class::*;
Expand All @@ -16,4 +17,5 @@ pub use metacall_future::*;
pub use metacall_null::*;
pub use metacall_object::*;
pub use metacall_pointer::*;
pub use metacall_tags::*;
pub use metacall_value::*;
15 changes: 7 additions & 8 deletions source/ports/rs_port/tests/inlines_test.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use metacall::{
initialize,
inline::{node, py, ts},
is_initialized,
load::{self, Tag},
is_initialized, load,
};

#[test]
Expand All @@ -11,30 +10,30 @@ fn inlines() {

assert!(is_initialized());

if load::from_memory(Tag::Python, "", None).is_ok() {
if load::from_memory(load::Tag::Python, "", None).is_ok() {
py! {
print("hello world")
}
}
if load::from_memory(Tag::Python, "", None).is_ok() {
if load::from_memory(load::Tag::Python, "", None).is_ok() {
py! {print("hello world")}
}

if load::from_memory(Tag::NodeJS, "", None).is_ok() {
if load::from_memory(load::Tag::NodeJS, "", None).is_ok() {
node! {
console.log("hello world");
}
}
if load::from_memory(Tag::NodeJS, "", None).is_ok() {
if load::from_memory(load::Tag::NodeJS, "", None).is_ok() {
node! {console.log("hello world")}
}

if load::from_memory(Tag::TypeScript, "", None).is_ok() {
if load::from_memory(load::Tag::TypeScript, "", None).is_ok() {
ts! {
console.log("hello world");
}
}
if load::from_memory(Tag::TypeScript, "", None).is_ok() {
if load::from_memory(load::Tag::TypeScript, "", None).is_ok() {
ts! {console.log("hello world")}
}
}
8 changes: 2 additions & 6 deletions source/ports/rs_port/tests/invalid_loaders_test.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use metacall::{
initialize, is_initialized,
load::{self, Tag},
MetaCallLoaderError,
};
use metacall::{initialize, is_initialized, load, MetaCallLoaderError};
use std::env;

#[test]
Expand All @@ -25,7 +21,7 @@ fn invalid_loaders() {

// We use JSM here because it is not implemented, it should fail
if let Err(MetaCallLoaderError::FromFileFailure) =
load::from_single_file(Tag::JSM, valid_file, None)
load::from_single_file(load::Tag::JSM, valid_file, None)
{
// Everything Ok
} else {
Expand Down
10 changes: 3 additions & 7 deletions source/ports/rs_port/tests/loaders_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use metacall::{
initialize, is_initialized,
load::{self, Tag},
load::{self},
metacall_no_arg,
};
use std::{
Expand All @@ -22,11 +22,7 @@ fn call_greet(test: &str, num: u32) {
}

fn load_from_memory_test() {
load::from_memory(Tag::NodeJS, SCRIPT1, None).unwrap();

call_greet("load_from_memory", 1);

load::from_memory(Tag::NodeJS, SCRIPT3, None).unwrap();
load::from_memory(load::Tag::NodeJS, SCRIPT3, None).unwrap();
}

fn load_from_file_test() {
Expand All @@ -40,7 +36,7 @@ fn load_from_file_test() {
temp_js.write_all(SCRIPT2.as_bytes()).unwrap();
temp_js.flush().unwrap();

load::from_single_file(Tag::NodeJS, temp_js_path, None).unwrap();
load::from_single_file(load::Tag::NodeJS, temp_js_path, None).unwrap();

call_greet("load_from_file", 2);

Expand Down
7 changes: 2 additions & 5 deletions source/ports/rs_port/tests/metacall_exception_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use metacall::{
initialize, is_initialized,
load::{self, Tag},
};
use metacall::{initialize, is_initialized, load};
use std::env;

#[test]
Expand All @@ -13,7 +10,7 @@ fn metacall_exception() {
let tests_dir = env::current_dir().unwrap().join("tests/scripts");
let js_test_file = tests_dir.join("script.js");

if load::from_single_file(Tag::NodeJS, js_test_file, None).is_ok() {
if load::from_single_file(load::Tag::NodeJS, js_test_file, None).is_ok() {
// This should not generate a segmentation fault
let val =
metacall::metacall_no_arg::<metacall::MetaCallException>("test_exception").unwrap();
Expand Down
6 changes: 3 additions & 3 deletions source/ports/rs_port/tests/metacall_handle_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use metacall::{
initialize, is_initialized,
load::{self, Handle, Tag},
load::{self, Handle},
metacall_handle_no_arg,
};

Expand All @@ -16,8 +16,8 @@ fn metacall_handle() {
let mut handle1 = Handle::new();
let mut handle2 = Handle::new();

let result1 = load::from_memory(Tag::NodeJS, SCRIPT1, Some(&mut handle1));
let result2 = load::from_memory(Tag::NodeJS, SCRIPT2, Some(&mut handle2));
let result1 = load::from_memory(load::Tag::NodeJS, SCRIPT1, Some(&mut handle1));
let result2 = load::from_memory(load::Tag::NodeJS, SCRIPT2, Some(&mut handle2));

assert!(result1.is_ok());
assert!(result2.is_ok());
Expand Down
9 changes: 4 additions & 5 deletions source/ports/rs_port/tests/metacall_test.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use metacall::{
initialize, is_initialized,
load::{self, Tag},
MetaCallClass, MetaCallException, MetaCallFunction, MetaCallFuture, MetaCallNull,
MetaCallObject, MetaCallPointer, MetaCallThrowable, MetaCallValue,
initialize, is_initialized, load, MetaCallClass, MetaCallException, MetaCallFunction,
MetaCallFuture, MetaCallNull, MetaCallObject, MetaCallPointer, MetaCallThrowable,
MetaCallValue,
};
use std::{any::Any, collections::HashMap, env, fmt::Debug};

Expand Down Expand Up @@ -372,7 +371,7 @@ fn metacall() {
let js_test_file = tests_dir.join("script.js");
let c_test_file = tests_dir.join("script.c");
let py_test_file = tests_dir.join("script.py");
let py_loaded = load::from_single_file(Tag::Python, py_test_file, None).is_ok();
let py_loaded = load::from_single_file(load::Tag::Python, py_test_file, None).is_ok();

if py_loaded {
test_buffer();
Expand Down