Expand description
METACALL is a library that allows calling functions, methods or procedures between programming languages. With METACALL you can transparently execute code from / to any programming language, for example, call TypeScript code from Rust. Click here for installation guide.
General usage example:
Let’s consider we have the following Typescript code:
sum.ts
export function sum(a: number, b: number): number {
return a + b;
}
Now let’s jump into Rust:
use metacall::{switch, metacall, loaders};
fn main() {
// Initialize Metacall at the top
let _metacall = switch::initialize().unwrap();
// Load the file (Checkout the loaders module for loading multiple files
// or loading from string)
loaders::from_single_file("ts", "sum.ts").unwrap();
// Call the sum function (Also checkout other metacall functions)
let sum = metacall::<f64>("sum", [1.0, 2.0]).unwrap();
assert_eq!(sum, 3.0);
}
Modules§
- inline
- Contains Metacall language inliners. Usage example: …
- loaders
- Contains Metacall loaders from file and memory. Usage example: …
Macros§
- match_
metacall_ value - Matches MetacallValue trait object. For example: …
- match_
metacall_ value_ mut - Same as match_metacall_value but gives a mutable reference. For example: …
- match_
metacall_ value_ ref - Same as match_metacall_value but gives a reference. For example: …
Structs§
- Metacall
Class - Represents Metacall Class. You can get this type when returned by a function or get a class by its name with from_name.
- Metacall
Exception - Represents Metacall exception. You can create an exception with new.
- Metacall
Function - Represents Metacall function.
- Metacall
Future - Represents MetacallFuture. Keep in mind that it’s not supported to pass a future as an argument.
- Metacall
Init Error - This error happens when it’s not possible to initialize the Metacall core. You can check your logs for more information.
- Metacall
Null - Represents NULL.
- Metacall
Object - Represents Metacall Object. You can get this type when returned by a function or create one from a class with create_object.
- Metacall
Pointer - Represents Metacall pointer. This type cannot be used in other languages. This type is highly unsafe so be careful!
- Metacall
String Conversion Error - This error may happen when passing contains a null character. You can access the original string and the NulError throughout this struct.
- Metacall
Throwable - Represents Metacall throwable. Keep in mind that it’s not supported to pass a throwable as an argument.
Enums§
- Metacall
Class From Name Error - This error may happen when trying to get a class by its name.
- Metacall
Error - This error may happen when trying to call a function.
- Metacall
GetAttribute Error - This error may happen when trying to get a class/object attribute.
- Metacall
Loader Error - This error may happen when loading a code. Check your logs for more information if you
get
FromFileFailure
orFromMemoryFailure
error variant. - Metacall
SetAttribute Error - This error may happen when trying to set a class/object attribute. Check your logs
if you get
SetAttributeFailure
error variant. - Metacall
Throwable Value - Different types of Throwable value.
Traits§
- Metacall
Value - Trait of any possible object in Metacall. Checkout match_metacall_value macro for matching trait objects of this trait. Let’ see what types we can use with an example: …
Functions§
- initialize
- Initializes Metacall. Always remember to store the output in a variable to avoid instant drop. For example: …
- metacall
- Calls a function with arguments. The generic parameter is the return type of the function you’re calling. Checkout MetacallValue for possible types. For example: …
- metacall_
no_ arg - Calls a function same as metacall without passing any arguments. For example: …
- metacall_
untyped - Calls a function same as metacall but returns a trait object of MetacallValue. This is useful when you don’t know the return type of that function or the function may return multiple types. Checkout match_metacall_value for unwrapping the inner value. For example: …
- metacall_
untyped_ no_ arg - Calls a function same as metacall_untyped without passing any arguments. For example: …
Type Aliases§
- Metacall
Future Handler - Function pointer type used for resolving/rejecting Metacall futures. The first argument is the result and the second argument is the data that you may want to access when the function gets called. Checkout MetacallFuture resolve or MetacallFuture reject for usage.