diff --git a/source/ports/rs_port/.vscode/settings.json b/source/ports/rs_port/.vscode/settings.json index c57b92269..8a76e8562 100644 --- a/source/ports/rs_port/.vscode/settings.json +++ b/source/ports/rs_port/.vscode/settings.json @@ -1,4 +1,8 @@ { + "[rust]": { + "editor.defaultFormatter": "rust-lang.rust-analyzer", + "editor.formatOnSave": true + }, "rust-analyzer.checkOnSave": true, "rust-analyzer.check.command": "clippy" } diff --git a/source/ports/rs_port/src/parsers.rs b/source/ports/rs_port/src/parsers.rs index 597af56a6..4a711d1fa 100644 --- a/source/ports/rs_port/src/parsers.rs +++ b/source/ports/rs_port/src/parsers.rs @@ -56,50 +56,126 @@ pub fn raw_to_metacallobj_leak( pub fn raw_to_metacallobj_untyped(ret: *mut c_void) -> Box { match (ret.is_null(), unsafe { metacall_value_id(ret) }) { (true, _) => metacallobj_result_wrap(MetaCallNull::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_BOOL) => metacallobj_result_wrap(bool::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_CHAR) => metacallobj_result_wrap(char::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_SHORT) => metacallobj_result_wrap(i16::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_INT) => metacallobj_result_wrap(i32::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_LONG) => metacallobj_result_wrap(i64::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_FLOAT) => metacallobj_result_wrap(f32::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_DOUBLE) => metacallobj_result_wrap(f64::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_STRING) => metacallobj_result_wrap(String::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_BUFFER) => metacallobj_result_wrap(>::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_ARRAY) => metacallobj_result_wrap(>::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_MAP) => metacallobj_result_wrap(>::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_PTR) => metacallobj_result_wrap(::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_FUTURE) => metacallobj_result_wrap(MetaCallFuture::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_FUNCTION) => metacallobj_result_wrap(MetaCallFunction::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_NULL) => metacallobj_result_wrap(MetaCallNull::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_CLASS) => metacallobj_result_wrap(MetaCallClass::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_OBJECT) => metacallobj_result_wrap(MetaCallObject::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_EXCEPTION) => metacallobj_result_wrap(MetaCallException::from_metacall_raw(ret)), - (_, metacall_value_id::METACALL_THROWABLE) => metacallobj_result_wrap(MetaCallThrowable::from_metacall_raw(ret)), + (_, metacall_value_id::METACALL_BOOL) => { + metacallobj_result_wrap(bool::from_metacall_raw(ret)) + } + (_, metacall_value_id::METACALL_CHAR) => { + metacallobj_result_wrap(char::from_metacall_raw(ret)) + } + (_, metacall_value_id::METACALL_SHORT) => { + metacallobj_result_wrap(i16::from_metacall_raw(ret)) + } + (_, metacall_value_id::METACALL_INT) => { + metacallobj_result_wrap(i32::from_metacall_raw(ret)) + } + (_, metacall_value_id::METACALL_LONG) => { + metacallobj_result_wrap(i64::from_metacall_raw(ret)) + } + (_, metacall_value_id::METACALL_FLOAT) => { + metacallobj_result_wrap(f32::from_metacall_raw(ret)) + } + (_, metacall_value_id::METACALL_DOUBLE) => { + metacallobj_result_wrap(f64::from_metacall_raw(ret)) + } + (_, metacall_value_id::METACALL_STRING) => { + metacallobj_result_wrap(String::from_metacall_raw(ret)) + } + (_, metacall_value_id::METACALL_BUFFER) => { + metacallobj_result_wrap(>::from_metacall_raw(ret)) + } + (_, metacall_value_id::METACALL_ARRAY) => { + metacallobj_result_wrap(>::from_metacall_raw(ret)) + } + (_, metacall_value_id::METACALL_MAP) => { + metacallobj_result_wrap(>::from_metacall_raw(ret)) + } + (_, metacall_value_id::METACALL_PTR) => { + metacallobj_result_wrap(::from_metacall_raw(ret)) + } + (_, metacall_value_id::METACALL_FUTURE) => { + metacallobj_result_wrap(MetaCallFuture::from_metacall_raw(ret)) + } + (_, metacall_value_id::METACALL_FUNCTION) => { + metacallobj_result_wrap(MetaCallFunction::from_metacall_raw(ret)) + } + (_, metacall_value_id::METACALL_NULL) => { + metacallobj_result_wrap(MetaCallNull::from_metacall_raw(ret)) + } + (_, metacall_value_id::METACALL_CLASS) => { + metacallobj_result_wrap(MetaCallClass::from_metacall_raw(ret)) + } + (_, metacall_value_id::METACALL_OBJECT) => { + metacallobj_result_wrap(MetaCallObject::from_metacall_raw(ret)) + } + (_, metacall_value_id::METACALL_EXCEPTION) => { + metacallobj_result_wrap(MetaCallException::from_metacall_raw(ret)) + } + (_, metacall_value_id::METACALL_THROWABLE) => { + metacallobj_result_wrap(MetaCallThrowable::from_metacall_raw(ret)) + } _ => metacallobj_result_wrap(MetaCallNull::from_metacall_raw(ret)), } } pub fn raw_to_metacallobj_untyped_leak(ret: *mut c_void) -> Box { match (ret.is_null(), unsafe { metacall_value_id(ret) }) { (true, _) => metacallobj_result_wrap(MetaCallNull::from_metacall_raw_leak(ret)), - (_, metacall_value_id::METACALL_BOOL) => metacallobj_result_wrap(bool::from_metacall_raw_leak(ret)), - (_, metacall_value_id::METACALL_CHAR) => metacallobj_result_wrap(char::from_metacall_raw_leak(ret)), - (_, metacall_value_id::METACALL_SHORT) => metacallobj_result_wrap(i16::from_metacall_raw_leak(ret)), - (_, metacall_value_id::METACALL_INT) => metacallobj_result_wrap(i32::from_metacall_raw_leak(ret)), - (_, metacall_value_id::METACALL_LONG) => metacallobj_result_wrap(i64::from_metacall_raw_leak(ret)), - (_, metacall_value_id::METACALL_FLOAT) => metacallobj_result_wrap(f32::from_metacall_raw_leak(ret)), - (_, metacall_value_id::METACALL_DOUBLE) => metacallobj_result_wrap(f64::from_metacall_raw_leak(ret)), - (_, metacall_value_id::METACALL_STRING) => metacallobj_result_wrap(String::from_metacall_raw_leak(ret)), - (_, metacall_value_id::METACALL_BUFFER) => metacallobj_result_wrap(>::from_metacall_raw_leak(ret)), - (_, metacall_value_id::METACALL_ARRAY) => metacallobj_result_wrap(>::from_metacall_raw_leak(ret)), - (_, metacall_value_id::METACALL_MAP) => { metacallobj_result_wrap(>::from_metacall_raw_leak(ret)) } - (_, metacall_value_id::METACALL_PTR) => metacallobj_result_wrap(::from_metacall_raw_leak(ret)), - (_, metacall_value_id::METACALL_FUTURE) => metacallobj_result_wrap(MetaCallFuture::from_metacall_raw_leak(ret)), - (_, metacall_value_id::METACALL_FUNCTION) => metacallobj_result_wrap(MetaCallFunction::from_metacall_raw_leak(ret)), - (_, metacall_value_id::METACALL_NULL) => metacallobj_result_wrap(MetaCallNull::from_metacall_raw_leak(ret)), - (_, metacall_value_id::METACALL_CLASS) => metacallobj_result_wrap(MetaCallClass::from_metacall_raw_leak(ret)), - (_, metacall_value_id::METACALL_OBJECT) => metacallobj_result_wrap(MetaCallObject::from_metacall_raw_leak(ret)), - (_, metacall_value_id::METACALL_EXCEPTION) => metacallobj_result_wrap(MetaCallException::from_metacall_raw_leak(ret)), - (_, metacall_value_id::METACALL_THROWABLE) => metacallobj_result_wrap(MetaCallThrowable::from_metacall_raw_leak(ret)), + (_, metacall_value_id::METACALL_BOOL) => { + metacallobj_result_wrap(bool::from_metacall_raw_leak(ret)) + } + (_, metacall_value_id::METACALL_CHAR) => { + metacallobj_result_wrap(char::from_metacall_raw_leak(ret)) + } + (_, metacall_value_id::METACALL_SHORT) => { + metacallobj_result_wrap(i16::from_metacall_raw_leak(ret)) + } + (_, metacall_value_id::METACALL_INT) => { + metacallobj_result_wrap(i32::from_metacall_raw_leak(ret)) + } + (_, metacall_value_id::METACALL_LONG) => { + metacallobj_result_wrap(i64::from_metacall_raw_leak(ret)) + } + (_, metacall_value_id::METACALL_FLOAT) => { + metacallobj_result_wrap(f32::from_metacall_raw_leak(ret)) + } + (_, metacall_value_id::METACALL_DOUBLE) => { + metacallobj_result_wrap(f64::from_metacall_raw_leak(ret)) + } + (_, metacall_value_id::METACALL_STRING) => { + metacallobj_result_wrap(String::from_metacall_raw_leak(ret)) + } + (_, metacall_value_id::METACALL_BUFFER) => { + metacallobj_result_wrap(>::from_metacall_raw_leak(ret)) + } + (_, metacall_value_id::METACALL_ARRAY) => { + metacallobj_result_wrap(>::from_metacall_raw_leak(ret)) + } + (_, metacall_value_id::METACALL_MAP) => { + metacallobj_result_wrap(>::from_metacall_raw_leak(ret)) + } + (_, metacall_value_id::METACALL_PTR) => { + metacallobj_result_wrap(::from_metacall_raw_leak(ret)) + } + (_, metacall_value_id::METACALL_FUTURE) => { + metacallobj_result_wrap(MetaCallFuture::from_metacall_raw_leak(ret)) + } + (_, metacall_value_id::METACALL_FUNCTION) => { + metacallobj_result_wrap(MetaCallFunction::from_metacall_raw_leak(ret)) + } + (_, metacall_value_id::METACALL_NULL) => { + metacallobj_result_wrap(MetaCallNull::from_metacall_raw_leak(ret)) + } + (_, metacall_value_id::METACALL_CLASS) => { + metacallobj_result_wrap(MetaCallClass::from_metacall_raw_leak(ret)) + } + (_, metacall_value_id::METACALL_OBJECT) => { + metacallobj_result_wrap(MetaCallObject::from_metacall_raw_leak(ret)) + } + (_, metacall_value_id::METACALL_EXCEPTION) => { + metacallobj_result_wrap(MetaCallException::from_metacall_raw_leak(ret)) + } + (_, metacall_value_id::METACALL_THROWABLE) => { + metacallobj_result_wrap(MetaCallThrowable::from_metacall_raw_leak(ret)) + } _ => metacallobj_result_wrap(MetaCallNull::from_metacall_raw_leak(ret)), } } diff --git a/source/ports/rs_port/src/types/metacall_future.rs b/source/ports/rs_port/src/types/metacall_future.rs index fa911d134..23556c613 100644 --- a/source/ports/rs_port/src/types/metacall_future.rs +++ b/source/ports/rs_port/src/types/metacall_future.rs @@ -16,9 +16,9 @@ use std::{ pub type MetaCallFutureHandler = fn(Box, Box); /// Represents MetaCallFuture. Keep in mind that it's not supported to pass a future as an argument. -/// +/// /// ## **Usage example:** -/// +/// /// **Javascript Code:** /// ```javascript /// function doubleValueAfterTime(value, delay) { @@ -33,20 +33,20 @@ pub type MetaCallFutureHandler = fn(Box, Box("doubleValueAfterTime", [1, 2000]).unwrap(); /// future.then(resolve).catch(reject).await_fut(); /// } @@ -161,47 +161,47 @@ impl MetaCallFuture { } /// Adds a resolve callback. - /// + /// /// ## **Usage example:** - /// - /// + /// + /// /// ```javascript /// // Javascript script - /// + /// /// function func_always_rejects(value, delay) { /// return new Promise((resolve) => { - /// resolve('Resolve message.'); + /// resolve('Resolve message.'); /// }); /// } /// ``` /// **Calling Example:** - /// + /// /// ```rust /// use metacall::{MetaCallValue, MetaCallFuture, metacall_no_args}; /// fn calling() { /// fn reject(result: impl MetaCallValue, _: impl MetaCallValue) { /// println!("Resolve:: {:#?}", result); // Resolve:: "Resolve message" /// } - /// + /// /// let future = metacall_no_args::("func_always_resolve").unwrap(); /// future.then(resolve).catch(reject).await_fut(); /// } /// ``` pub fn then(mut self, resolve: MetaCallFutureHandler) -> Self { self.resolve = Some(resolve); - + self } - + /// Adds a reject callback. - /// + /// /// ## **Usage example:** - /// + /// /// ```javascript /// // Javascript script /// function func_always_rejects(value, delay) { /// return new Promise((_, reject) => { - /// reject('Error: Reject message.'); + /// reject('Error: Reject message.'); /// }); /// } /// ``` @@ -212,7 +212,7 @@ impl MetaCallFuture { /// fn reject(error: impl MetaCallValue, _: impl MetaCallValue) { /// println!("Reject:: error: {:#?}", error); // Reject:: error: "Error: Reject message" /// } - /// + /// /// let future = metacall_no_args::("func_always_rejects").unwrap(); /// future.then(resolve).catch(reject).await_fut(); /// } @@ -224,11 +224,11 @@ impl MetaCallFuture { } /// Adds data to use it inside the `resolver` and `reject`. - /// + /// /// Example: /// ```rust /// use metacall::{MetaCallValue, MetaCallFuture, metacall}; - /// + /// /// fn run() { /// let x = 10; /// fn resolve(result: impl MetaCallValue, data: impl MetaCallValue) {