Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add return types to the Rust stable ic types #2520

Merged
merged 2 commits into from
Jan 16, 2025
Merged
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
Binary file modified canister_templates/experimental.wasm
Binary file not shown.
Binary file modified canister_templates/stable.wasm
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use ic_cdk::api::call::accept_message;
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, || accept_message())
Function::new(ctx, || -> () { accept_message() })
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ic_cdk::api::call::arg_data_raw;
use rquickjs::{Ctx, Function, Result, TypedArray};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx.clone(), move || {
Function::new(ctx.clone(), move || -> Result<TypedArray<u8>> {
TypedArray::<u8>::new(ctx.clone(), arg_data_raw())
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ic_cdk::api::caller;
use rquickjs::{Ctx, Function, Result, TypedArray};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx.clone(), move || {
Function::new(ctx.clone(), move || -> Result<TypedArray<u8>> {
TypedArray::<u8>::new(ctx.clone(), caller().as_slice())
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use ic_cdk::api::canister_balance128;
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, || canister_balance128().to_string())
Function::new(ctx, || -> String { canister_balance128().to_string() })
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ic_cdk::api::canister_version;
use rquickjs::{BigInt, Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx.clone(), move || {
Function::new(ctx.clone(), move || -> Result<BigInt> {
BigInt::from_u64(ctx.clone(), canister_version())
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ic_cdk::api::is_controller;
use rquickjs::{Ctx, Function, Result, TypedArray};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, |principal_bytes: TypedArray<u8>| {
Function::new(ctx, |principal_bytes: TypedArray<u8>| -> bool {
let principal = Principal::from_slice(principal_bytes.as_ref());

is_controller(&principal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use ic_cdk::api::call::method_name;
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, || method_name())
Function::new(ctx, || -> String { method_name() })
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use ic_cdk::api::call::msg_cycles_available128;
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, || msg_cycles_available128().to_string())
Function::new(ctx, || -> String { msg_cycles_available128().to_string() })
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use ic_cdk::api::call::msg_cycles_refunded128;
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, || msg_cycles_refunded128().to_string())
Function::new(ctx, || -> String { msg_cycles_refunded128().to_string() })
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ic_cdk::print;
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, |message: String| {
Function::new(ctx, |message: String| -> () {
print(message);
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use ic_cdk::api::call::reject;
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, |message: String| reject(&message))
Function::new(ctx, |message: String| -> () { reject(&message) })
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ic_cdk::api::call::{reject_code, RejectionCode};
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, || {
Function::new(ctx, || -> u32 {
let reject_code = reject_code();

match reject_code {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use ic_cdk::api::call::reject_message;
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, || reject_message())
Function::new(ctx, || -> String { reject_message() })
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ use ic_cdk::api::call::reply_raw;
use rquickjs::{Ctx, Function, Result, TypedArray};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, |bytes: TypedArray<u8>| reply_raw(bytes.as_ref()))
Function::new(ctx, |bytes: TypedArray<u8>| -> () {
reply_raw(bytes.as_ref())
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ic_cdk::api::set_certified_data;
use rquickjs::{Ctx, Function, Result, TypedArray};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, |bytes: TypedArray<u8>| {
Function::new(ctx, |bytes: TypedArray<u8>| -> () {
set_certified_data(bytes.as_ref())
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rquickjs::{Ctx, Function, Result};
use crate::{stable_b_tree_map::STABLE_B_TREE_MAPS, MEMORY_MANAGER_REF_CELL};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, |memory_id: u8| {
Function::new(ctx, |memory_id: u8| -> () {
STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| {
let mut stable_b_tree_maps = stable_b_tree_maps.borrow_mut();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// TODO readdress the workarounds below once this issue is resolved: https://github.com/DelSkayn/rquickjs/issues/413

use ic_cdk::api::trap;
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, |message: String| cast_trap(message))
Function::new(ctx, |message: String| -> () { cast_trap(message) })
}

/// This function is needed to handle the never type (!) return from trap() in a Function::new closure.
Expand Down
Loading