metacall/
lib.rs

1#![warn(clippy::all)]
2#![allow(
3    clippy::not_unsafe_ptr_arg_deref,
4    clippy::boxed_local,
5    clippy::tabs_in_doc_comments,
6    clippy::needless_doctest_main
7)]
8/*
9 *	MetaCall Library by Parra Studios
10 *	A library for providing a foreign function interface calls.
11 *
12 *	Copyright (C) 2016 - 2025 Vicente Eduardo Ferrer Garcia <vic798@gmail.com>
13 *
14 *	Licensed under the Apache License, Version 2.0 (the "License");
15 *	you may not use this file except in compliance with the License.
16 *	You may obtain a copy of the License at
17 *
18 *		http://www.apache.org/licenses/LICENSE-2.0
19 *
20 *	Unless required by applicable law or agreed to in writing, software
21 *	distributed under the License is distributed on an "AS IS" BASIS,
22 *	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 *	See the License for the specific language governing permissions and
24 *	limitations under the License.
25 *
26 */
27
28//! [METACALL](https://github.com/metacall/core) is a library that allows calling functions,
29//! methods or procedures between programming languages. With METACALL you can transparently
30//! execute code from / to any programming language, for example, call TypeScript code from Rust.
31//! Click [here](https://github.com/metacall/install) for installation guide.
32//!
33//! General usage example:
34//! Let's consider we have the following Typescript code:
35//! `sum.ts`
36//! ``` javascript
37//! export function sum(a: number, b: number): number {
38//!	    return a + b;
39//! }
40//! ```
41//! Now let's jump into Rust:
42//!
43//! ```
44//! use metacall::{initialize, metacall, load};
45//!
46//! fn main() {
47//!     // Initialize MetaCall at the top
48//!     let _metacall = initialize().unwrap();
49//!     
50//!     // Load the file (Checkout the loaders module for loading multiple files
51//!     // or loading from string)
52//!     load::from_single_file("ts", "sum.ts").unwrap();
53//!
54//!     // Call the sum function (Also checkout other metacall functions)
55//!     let sum = metacall::<f64>("sum", [1.0, 2.0]).unwrap();
56//!
57//!     assert_eq!(sum, 3.0);
58//! }
59//!
60//! ```
61
62pub(crate) mod cast;
63pub(crate) mod helpers;
64pub(crate) use macros::private_macros::*;
65
66/// Contains MetaCall loaders from file and memory. Usage example: ...
67/// ```
68/// // Loading a single file with Nodejs.
69/// metacall::load::from_single_file("node", "index.js").unwrap();
70///
71/// // Loading multiple files with Nodejs.
72/// metacall::load::from_file("node", ["index.js", "main.js"]).unwrap();
73///
74/// // Loading a string with Nodejs.
75/// let script = "function greet() { return 'hi there!' }; module.exports = { greet };";
76/// metacall::load::from_memory("node", script).unwrap();
77/// ```
78pub mod load;
79
80mod types;
81
82#[doc(hidden)]
83pub mod macros;
84
85#[doc(hidden)]
86pub use types::*;
87
88#[doc(hidden)]
89mod init;
90
91pub use cast::metacall_box;
92pub use init::initialize;
93pub use init::is_initialized;
94
95#[path = "metacall.rs"]
96mod metacall_mod;
97pub use metacall_mod::*;
98
99/// Contains MetaCall language inliners. Usage example: ...
100/// ```
101/// // Python
102/// py! {
103///     print("hello world")
104/// }
105///
106/// // Nodejs
107/// node! {
108///     console.log("hello world");
109/// }
110///
111/// // Typescript
112/// ts! {
113///     console.log("hello world");
114/// }
115/// ```
116pub mod inline {
117    pub use metacall_inline::*;
118}
119
120#[allow(warnings)]
121#[doc(hidden)]
122pub mod bindings;