Skip to content

Commit

Permalink
add return types to the Rust stable ic types
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Jan 16, 2025
1 parent 0d6eff5 commit 65c6c09
Show file tree
Hide file tree
Showing 18 changed files with 21 additions and 17 deletions.
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

0 comments on commit 65c6c09

Please sign in to comment.